private static Object appendValueToArray(Object jsonObject, String path, Object value) {
        Object targetNode = JSONPath.eval(jsonObject, path);

        if (targetNode == null) {
            throw new IllegalArgumentException("Target path does not exist.");
        }

        // If it is already an array type, simply append it
        if (targetNode instanceof JSONArray) {
            JSONArray array = (JSONArray) targetNode;
            array.add(value);
        }
        // If it is a non array type, convert it to an array and append it
        else {
            JSONArray newArray = new JSONArray();
            newArray.add(targetNode);
            newArray.add(value);
            if ("$".equals(path)) {
                return newArray;
            }
            JSONPath.set(jsonObject, path, newArray);
        }
        return jsonObject;
    }
Append values to an array at a specified path

@param jsonObject The object parsed by jsonDoc
@param path       path
@param value      value
inlong-sdk/transform-sdk/src/main/java/org/apache/inlong/sdk/transform/process/function/json/JsonArrayAppendFunction.java