{"record":{"id":"7a324f46ec23dc92","repo":"json-path/JsonPath","slug":"could-not-parse-criteria","errorCode":null,"errorMessage":"Could not parse criteria","messagePattern":"Could not parse criteria","errorType":"validation","errorClass":"InvalidPathException","httpStatus":null,"severity":"error","filePath":"json-path/src/main/java/com/jayway/jsonpath/Criteria.java","lineNumber":479,"sourceCode":"     * Parse the provided criteria\n     *\n     * Deprecated use {@link Filter#parse(String)}\n     *\n     * @param criteria\n     * @return a criteria\n     */\n    @Deprecated\n    public static Criteria parse(String criteria) {\n        if(criteria == null){\n            throw new InvalidPathException(\"Criteria can not be null\");\n        }\n        String[] split = criteria.trim().split(\" \");\n        if(split.length == 3){\n            return create(split[0], split[1], split[2]);\n        } else if(split.length == 1){\n            return create(split[0], \"EXISTS\", \"true\");\n        } else {\n            throw new InvalidPathException(\"Could not parse criteria\");\n        }\n    }\n\n    /**\n     * Creates a new criteria\n     * @param left path to evaluate in criteria\n     * @param operator operator\n     * @param right expected value\n     * @return a new Criteria\n     */\n    @Deprecated\n    public static Criteria create(String left, String operator, String right) {\n        Criteria criteria = new Criteria(ValueNode.toValueNode(left));\n        criteria.criteriaType = RelationalOperator.fromString(operator);\n        criteria.right = ValueNode.toValueNode(right);\n        return criteria;\n    }\n","sourceCodeStart":461,"sourceCodeEnd":497,"githubUrl":"https://github.com/json-path/JsonPath/blob/62a4c9f0f65ba3f625aa0867d64c528ba72d09ec/json-path/src/main/java/com/jayway/jsonpath/Criteria.java#L461-L497","documentation":"Criteria.parse(String) splits the criteria on single spaces and only understands exactly 1 token (bare path, EXISTS true) or 3 tokens (path operator value). Any other token count throws InvalidPathException 'Could not parse criteria'.","triggerScenarios":"Criteria.parse(\"$.a == 1 extra\") (4 tokens), Criteria.parse(\"$.a ==\") (2 tokens), or criteria containing multi-space separators that produce empty tokens after split.","commonSituations":"Users writing filter strings with extra whitespace, compound conditions ('$.a == 1 and $.b == 2'), or operators containing spaces — formats parse() never supported.","solutions":["Ensure the string is exactly 'path operator value' or a bare path.","Replace multiple spaces with single spaces before calling parse.","Express compound logic via Filter.filter(where(\"$.a\").eq(1).and(\"$.b\").eq(2)) instead of a single string.","Migrate to the programmatic Criteria/Filter API and abandon string parsing."],"exampleFix":"// before\nCriteria c = Criteria.parse(\"$.age  ==  30\");\n// after\nCriteria c = Criteria.create(\"$.age\", \"==\", \"30\");\n// or\nFilter f = Filter.filter(Criteria.where(\"$.age\").is(30));","handlingStrategy":"validation","validationCode":"String[] parts = criteria.trim().split(\"\\\\s+\");\nif (parts.length != 1 && parts.length != 3) throw new IllegalArgumentException(\"criteria must be 'path' or 'path op value': \" + criteria);","typeGuard":null,"tryCatchPattern":"try {\n    Criteria c = Criteria.parse(criteria);\n} catch (InvalidPathException e) {\n    log.error(\"Unparseable criteria '{}': {}\", criteria, e.getMessage());\n    throw e;\n}","preventionTips":["Normalize whitespace before parsing.","Build filters programmatically (Criteria.where) instead of via strings.","Document the accepted 'path op value' format where criteria strings are configured."],"tags":["jsonpath","filter","parsing","deprecated"],"backgroundTag":"invalid-argument-format","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"}