{"record":{"id":"486f1aff35f14103","repo":"json-path/JsonPath","slug":"options-as-path-list-and-always-return-list-are-no","errorCode":null,"errorMessage":"Options AS_PATH_LIST and ALWAYS_RETURN_LIST are not allowed when using path functions!","messagePattern":"Options AS_PATH_LIST and ALWAYS_RETURN_LIST are not allowed when using path functions!","errorType":"exception","errorClass":"JsonPathException","httpStatus":null,"severity":"error","filePath":"json-path/src/main/java/com/jayway/jsonpath/JsonPath.java","lineNumber":177,"sourceCode":"     * the {@link JsonProvider}\n     *\n     * @param jsonObject    a container Object\n     * @param configuration configuration to use\n     * @param <T>           expected return type\n     * @return object(s) matched by the given path\n     */\n    @SuppressWarnings(\"unchecked\")\n    public <T> T read(Object jsonObject, Configuration configuration) {\n        boolean optAsPathList = configuration.containsOption(AS_PATH_LIST);\n        boolean optAlwaysReturnList = configuration.containsOption(Option.ALWAYS_RETURN_LIST);\n        boolean optSuppressExceptions = configuration.containsOption(Option.SUPPRESS_EXCEPTIONS);\n\n        if (path.isFunctionPath()) {\n            if (optAsPathList || optAlwaysReturnList) {\n                if (optSuppressExceptions) {\n                    return (T) (path.isDefinite() ? null : configuration.jsonProvider().createArray());\n                }\n                throw new JsonPathException(\"Options \" + AS_PATH_LIST + \" and \" + ALWAYS_RETURN_LIST + \" are not allowed when using path functions!\");\n            }\n            EvaluationContext evaluationContext = path.evaluate(jsonObject, jsonObject, configuration);\n            if (optSuppressExceptions && evaluationContext.getPathList().isEmpty()) {\n                return (T) (path.isDefinite() ? null : configuration.jsonProvider().createArray());\n            }\n            return evaluationContext.getValue(true);\n        } else if (optAsPathList) {\n            EvaluationContext evaluationContext = path.evaluate(jsonObject, jsonObject, configuration);\n            if (optSuppressExceptions && evaluationContext.getPathList().isEmpty()) {\n                return (T) configuration.jsonProvider().createArray();\n            }\n            return (T) evaluationContext.getPath();\n        } else {\n            EvaluationContext evaluationContext = path.evaluate(jsonObject, jsonObject, configuration);\n            if (optSuppressExceptions && evaluationContext.getPathList().isEmpty()) {\n                if (optAlwaysReturnList) {\n                    return (T) configuration.jsonProvider().createArray();\n                } else {","sourceCodeStart":159,"sourceCodeEnd":195,"githubUrl":"https://github.com/json-path/JsonPath/blob/62a4c9f0f65ba3f625aa0867d64c528ba72d09ec/json-path/src/main/java/com/jayway/jsonpath/JsonPath.java#L159-L195","documentation":"When a JsonPath uses functions (e.g. .length(), .min(), .max()), the library evaluates the function to a single computed value; wrapping that in AS_PATH_LIST (return paths instead of values) or ALWAYS_RETURN_LIST (always wrap in a list) is meaningless, so JsonPathException is thrown. With suppressExceptions enabled it quietly returns null/empty array instead.","triggerScenarios":"JsonPath.read(json, \"$.items.length()\", Configuration.builder().options(Option.AS_PATH_LIST).build()) or the same with Option.ALWAYS_RETURN_LIST — any read where path.isFunctionPath() and either option is set.","commonSituations":"Developers reusing a shared Configuration with ALWAYS_RETURN_LIST for all reads, then reading a function path like $.array.length(); or using path-list mode to introspect paths and hitting a function path.","solutions":["Remove AS_PATH_LIST/ALWAYS_RETURN_LIST from the Configuration used for function paths.","Build a separate Configuration without those options for function reads.","If list-wrapping is needed, wrap the result yourself: Arrays.asList(JsonPath.read(json, \"$.items.length()\")).","Check path.isFunctionPath() before choosing the configuration."],"exampleFix":"// before\nConfiguration conf = Configuration.builder().options(Option.ALWAYS_RETURN_LIST).build();\nint len = JsonPath.using(conf).read(json, \"$.items.length()\");\n// after\nint len = JsonPath.read(json, \"$.items.length()\");","handlingStrategy":"validation","validationCode":"if (path.isFunctionPath() && (conf.getOptions().contains(Option.AS_PATH_LIST) || conf.getOptions().contains(Option.ALWAYS_RETURN_LIST))) {\n    conf = Configuration.builder().build(); // drop conflicting options\n}","typeGuard":null,"tryCatchPattern":"try {\n    return JsonPath.using(conf).read(json, functionPath);\n} catch (JsonPathException e) {\n    if (e.getMessage().contains(\"not allowed when using path functions\")) {\n        return JsonPath.read(json, functionPath); // retry without options\n    }\n    throw e;\n}","preventionTips":["Keep two configurations: one plain for function paths, one with options otherwise.","Check isFunctionPath() before selecting a configuration.","Do not globally enable ALWAYS_RETURN_LIST across all reads."],"tags":["jsonpath","options","path-functions","conflicting-options"],"backgroundTag":"conflicting-config-options","analyzedSha":"62a4c9f0f65ba3f625aa0867d64c528ba72d09ec","analyzedAt":"2026-09-11T11:36:00.448Z","contentChangedAt":"2026-09-11T11:36:00.448Z","schemaVersion":2},"datasetVersion":"2026-09-14T05:17:10.506Z"}