{"record":{"id":"467667bc4a854676","repo":"json-path/JsonPath","slug":"expected-null-value","errorCode":null,"errorMessage":"Expected <null> value","messagePattern":"Expected <null> value","errorType":"exception","errorClass":"InvalidPathException","httpStatus":null,"severity":"error","filePath":"json-path/src/main/java/com/jayway/jsonpath/internal/filter/FilterCompiler.java","lineNumber":253,"sourceCode":"            }\n        }\n\n        CharSequence operator = filter.subSequence(begin, filter.position());\n        logger.trace(\"Operator from {} to {} -> [{}]\", begin, filter.position()-1, operator);\n        return RelationalOperator.fromString(operator.toString());\n    }\n\n    private NullNode readNullLiteral() {\n        int begin = filter.position();\n        if(filter.currentChar() == NULL && filter.inBounds(filter.position() + 3)){\n            CharSequence nullValue = filter.subSequence(filter.position(), filter.position() + 4);\n            if(\"null\".equals(nullValue.toString())){\n                logger.trace(\"NullLiteral from {} to {} -> [{}]\", begin, filter.position()+3, nullValue);\n                filter.incrementPosition(nullValue.length());\n                return ValueNode.createNullNode();\n            }\n        }\n        throw new InvalidPathException(\"Expected <null> value\");\n    }\n\n    private JsonNode readJsonLiteral(){\n        int begin = filter.position();\n\n        char openChar = filter.currentChar();\n\n        assert openChar == OPEN_ARRAY || openChar == OPEN_OBJECT;\n\n        char closeChar = openChar == OPEN_ARRAY ? CLOSE_ARRAY : CLOSE_OBJECT;\n\n        int closingIndex = filter.indexOfMatchingCloseChar(filter.position(), openChar, closeChar, true, false);\n        if (closingIndex == -1) {\n            throw new InvalidPathException(\"String not closed. Expected \" + SINGLE_QUOTE + \" in \" + filter);\n        } else {\n            filter.setPosition(closingIndex + 1);\n        }\n        CharSequence json = filter.subSequence(begin, filter.position());","sourceCodeStart":235,"sourceCodeEnd":271,"githubUrl":"https://github.com/json-path/JsonPath/blob/62a4c9f0f65ba3f625aa0867d64c528ba72d09ec/json-path/src/main/java/com/jayway/jsonpath/internal/filter/FilterCompiler.java#L235-L271","documentation":"Thrown by FilterCompiler.readNullLiteral when a token started as a potential null literal (beginning with 'n') does not spell exactly 'null'. readLiteral dispatches to this method on a candidate token, and if the characters do not match the reserved word, the compiler has no value node to produce and raises 'Expected <null> value'. It indicates a misspelled or partial null keyword inside the filter predicate.","triggerScenarios":"A filter predicate containing a near-null token where a literal is expected: \"$[?(@.a == nul)]\", \"$[?(@.a == Null)]\" (case-sensitive), \"$[?(@.a == none)]\"; triggered via Filter.compile or JsonPath.parse(...).read(path) on an inline filter.","commonSituations":"Language-habit casing ('Null'/'NULL' from SQL or C#, Python's 'None'); truncated strings from templating; trying to compare against a value that starts with 'n' without quoting it as a string.","solutions":["Spell the keyword exactly as lowercase 'null': \"$[?(@.a == null)]\"","If the value is not meant as null, quote it as a string literal: \"$[?(@.a == 'null')]\"","Remember JsonPath literals are case-sensitive — 'Null' and 'NULL' are not accepted","For existence checks on missing fields, use an existence-style predicate instead of a misspelled null keyword"],"exampleFix":"// before\nString path = \"$[?(@.middleName == Null)]\";\n// after\nString path = \"$[?(@.middleName == null)]\";","handlingStrategy":"type-guard","validationCode":"// Normalize casing/keyword typos before compiling\nString normalizeNull(String predicate) {\n    return predicate.replaceAll(\"(?<=\\\\s|=|!)\\\\s*(Null|NULL|None|nil)\\\\b\", \"null\");\n}\n// normalizeNull(\"$[?(@.a == None)]\") -> \"$[?(@.a == null)]\"","typeGuard":"static boolean usesCorrectNullKeyword(String filter) {\n    return !java.util.regex.Pattern.compile(\"(Null|NULL|None|nil|nul)\").matcher(filter).find();\n}","tryCatchPattern":"try {\n    Object v = JsonPath.parse(json).read(path);\n} catch (InvalidPathException e) {\n    if (e.getMessage().contains(\"Expected <null> value\")) {\n        throw new IllegalArgumentException(\"Use lowercase 'null' literal in filter: \" + path);\n    }\n    throw e;\n}","preventionTips":["The null keyword is lowercase and exact: null — 'Null', 'NULL', 'None' all fail","Quote a non-keyword value with single quotes: @.a == 'null'","Normalize user input through a sanitizer that fixes known keyword typos","Add compile-time tests for all literals used in shipped filter expressions"],"tags":["json-path","filter-compiler","null-literal","path-syntax"],"backgroundTag":"invalid-path-expression","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"}