{"record":{"id":"04d8d46e471c779d","repo":"karatelabs/karate","slug":"invalid-literal-expected-null","errorCode":null,"errorMessage":"Invalid literal — expected 'null'","messagePattern":"Invalid literal — expected 'null'","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"karate-js/src/main/java/io/karatelabs/js/JsonParser.java","lineNumber":343,"sourceCode":"                if (pos + 4 <= len && s.charAt(pos + 1) == 'r' && s.charAt(pos + 2) == 'u' && s.charAt(pos + 3) == 'e') {\n                    pos += 4;\n                    return Boolean.TRUE;\n                }\n                throw syntaxError(\"Invalid literal — expected 'true'\");\n            }\n            if (pos + 5 <= len && s.charAt(pos + 1) == 'a' && s.charAt(pos + 2) == 'l' && s.charAt(pos + 3) == 's' && s.charAt(pos + 4) == 'e') {\n                pos += 5;\n                return Boolean.FALSE;\n            }\n            throw syntaxError(\"Invalid literal — expected 'false'\");\n        }\n\n        private Object parseNull() {\n            if (pos + 4 <= len && s.charAt(pos + 1) == 'u' && s.charAt(pos + 2) == 'l' && s.charAt(pos + 3) == 'l') {\n                pos += 4;\n                return null;\n            }\n            throw syntaxError(\"Invalid literal — expected 'null'\");\n        }\n\n        void skipWs() {\n            while (pos < len) {\n                char c = s.charAt(pos);\n                if (c == ' ' || c == '\\t' || c == '\\n' || c == '\\r') {\n                    pos++;\n                } else {\n                    return;\n                }\n            }\n        }\n\n        JsErrorException syntaxError(String message) {\n            return JsErrorException.syntaxError(message + \" at position \" + pos);\n        }\n\n    }","sourceCodeStart":325,"sourceCodeEnd":361,"githubUrl":"https://github.com/karatelabs/karate/blob/a22eb90246d958d15a47bf436693d0121ad2812d/karate-js/src/main/java/io/karatelabs/js/JsonParser.java#L325-L361","documentation":"JSON literal parsing error in parseNull: the parser saw a token starting like 'null' but the following characters did not spell it out completely. Fires on malformed input such as 'nul' or 'nulx'; fix the literal spelling.","triggerScenarios":"Parsing JSON containing 'NULL' (SQL exports), 'None' (Python), 'nil'/'undefined' (other languages), or a truncated '{\"x\": nul}' where parseValue dispatched to parseNull on a token starting with 'n'.","commonSituations":"SQL query results dumped to JSON with NULL literals; Python data serialized via str() instead of json.dumps; templating that interpolates language-specific nulls; truncated responses.","solutions":["Replace the literal with lowercase 'null'.","Serialize with a JSON-aware encoder that maps None/NULL/nil to null.","Omit the key entirely if the intent is 'absent' rather than emitting a language-specific null.","Check for truncation if the token is a prefix of 'null'."],"exampleFix":"// before\nString json = \"{\\\"user\\\": None}\"; // Python str()\n// after\nString json = \"{\\\"user\\\": null}\"; // json.dumps handles this","handlingStrategy":"validation","validationCode":"// normalize language-specific nulls before parsing\nraw = raw.replaceAll(\"\\\\b(None|NULL|nil|undefined)\\\\b\", \"null\");\n// or omit absent keys entirely instead of emitting a null placeholder","typeGuard":null,"tryCatchPattern":"// Java\ntry {\n    Json json = Json.of(raw);\n} catch (Exception e) {\n    if (String.valueOf(e.getMessage()).contains(\"expected 'null'\")) {\n        raw = raw.replaceAll(\"\\\\b(None|NULL|nil)\\\\b\", \"null\");\n    } else { throw e; }\n}","preventionTips":["Only the exact lowercase literal 'null' is valid JSON.","Map None/NULL/nil through a JSON serializer, never string interpolation.","Omit keys for absent values instead of emitting language-specific nulls.","Check truncation if the token is a prefix like 'nul'."],"tags":["json","parser","null-literal","syntax-error"],"backgroundTag":"json-parse-error","analyzedSha":"a22eb90246d958d15a47bf436693d0121ad2812d","analyzedAt":"2026-09-12T09:01:00.220Z","contentChangedAt":"2026-09-12T09:01:00.220Z","schemaVersion":2},"datasetVersion":"2026-09-19T12:17:13.211Z"}