{"record":{"id":"9990eedccf68841e","repo":"karatelabs/karate","slug":"invalid-literal-expected-true","errorCode":null,"errorMessage":"Invalid literal — expected 'true'","messagePattern":"Invalid literal — expected 'true'","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"karate-js/src/main/java/io/karatelabs/js/JsonParser.java","lineNumber":329,"sourceCode":"            // karate-core stable (OAuth2Token.fromMap, W3cDriver, etc.).\n            try {\n                long v = Long.parseLong(lit);\n                if (v >= Integer.MIN_VALUE && v <= Integer.MAX_VALUE) {\n                    return (int) v;\n                }\n                return v;\n            } catch (NumberFormatException nfe) {\n                return new BigInteger(lit);\n            }\n        }\n\n        private Boolean parseBoolean() {\n            if (s.charAt(pos) == 't') {\n                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) {","sourceCodeStart":311,"sourceCodeEnd":347,"githubUrl":"https://github.com/karatelabs/karate/blob/a22eb90246d958d15a47bf436693d0121ad2812d/karate-js/src/main/java/io/karatelabs/js/JsonParser.java#L311-L347","documentation":"JsonParser.parseBoolean saw a token starting with 't' that is not exactly the four characters 'true'. The parser only accepts exact JSON literals — abbreviations like 'True', 'tru', or 'truthy' are rejected.","triggerScenarios":"Parsing JSON where a boolean value is 'True' (Python style), 'TRUE' (SQL/INI style), or a misspelled/shortened variant beginning with lowercase 't', e.g. '{\"flag\": tru}'.","commonSituations":"JSON generated from Python (repr of True), config files converted from properties/INI that used TRUE, typos in hand-written JSON, templating that emitted a language-specific boolean.","solutions":["Replace the literal with lowercase 'true'.","Fix the producing side to serialize booleans with JSON semantics (JSON.stringify, json.dumps with proper encoder) rather than language reprs.","For Python sources use json.dumps instead of str()/repr() so True becomes true.","Normalize case-sensitive boolean strings before parsing when converting config formats."],"exampleFix":"// before\nString json = \"{\\\"enabled\\\": True}\"; // Python repr\n// after\nString json = \"{\\\"enabled\\\": true}\";","handlingStrategy":"validation","validationCode":"// normalize non-JSON booleans before parsing\nraw = raw.replaceAll(\"\\\\bTrue\\\\b\", \"true\").replaceAll(\"\\\\bTRUE\\\\b\", \"true\");\n// flag remaining suspects:\nif (raw.matches(\".*\\\\btru?[a-z]*\\\\b(?!e\\\\s*[: Deadline,}\\\\]]).*\")) { /* inspect */ }","typeGuard":null,"tryCatchPattern":"// Java\ntry {\n    Json json = Json.of(raw);\n} catch (Exception e) {\n    if (String.valueOf(e.getMessage()).contains(\"expected 'true'\")) {\n        raw = raw.replaceAll(\"\\\\b(True|TRUE)\\\\b\", \"true\");\n    } else { throw e; }\n}","preventionTips":["JSON booleans are lowercase only: true/false.","Use json.dumps (Python) rather than str()/repr() when generating payloads.","Normalize booleans when converting INI/SQL/YAML data to JSON.","Add schema validation to catch wrong literal types early."],"tags":["json","parser","boolean-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"}