private String jsonArrayInsert(String jsonDoc, ArrayList<Object> pathValuePairs) {
        if (jsonDoc == null || pathValuePairs == null || pathValuePairs.size() % 2 != 0) {
            return null;
        }

        Object jsonObject = JSON.parse(jsonDoc);

        for (int i = 0; i < pathValuePairs.size(); i += 2) {
            String path = (String) pathValuePairs.get(i);
            Object value = pathValuePairs.get(i + 1);

            if (!path.endsWith("]")) {
                throw new IllegalArgumentException("Path must end with an array index: " + path);
            }

            // Find the parent path
            String parentPath = path.substring(0, path.lastIndexOf('['));
            Object parentNode = JSONPath.eval(jsonObject, parentPath);

            if (parentNode instanceof JSONArray) {
                // If the parent path is an array, perform the insert operation
                insertIntoArray((JSONArray) parentNode, path, value);
            } else if (parentNode instanceof JSONObject) {
                // If the parent path is an object, try inserting it into the array inside the object
                String arrayIndexPart = path.substring(path.lastIndexOf('['), path.lastIndexOf(']') + 1);
                handleArrayInsertionInObject((JSONObject) parentNode, arrayIndexPart, value);
            } else {
                throw new IllegalArgumentException("Invalid path or target node is not an array or object: " + path);
            }
        }

        return JSON.toJSONString(jsonObject);
    }
JsonArrayInsertFunction   ->  JSON_ARRAY_INSERT(json_doc, path, val[, path, val] ...)
description:
- return NULL if any argument is NULL;
- return the document inserted into the array.
Note: If multiple groups of parameters are passed in, the parameter subscripts of the latter groups
need to be based on the document subscripts after the previous group of parameters are updated.
inlong-sdk/transform-sdk/src/main/java/org/apache/inlong/sdk/transform/process/function/json/JsonArrayInsertFunction.java