{"record":{"id":"b6db8f385ec654ce","repo":"quarkusio/quarkus","slug":"unable-to-read-json-constant-for-expected","errorCode":null,"errorMessage":"Unable to read json constant for: ${expected}","messagePattern":"Unable to read json constant for: (.+?)","errorType":"exception","errorClass":"IllegalArgumentException","httpStatus":null,"severity":"error","filePath":"independent-projects/bootstrap/json/src/main/java/io/quarkus/bootstrap/json/JsonReader.java","lineNumber":309,"sourceCode":"        return isFraction;\n    }\n\n    private void ignoreDigits() {\n        while (position < length) {\n            final int ch = peekChar();\n            if (!Character.isDigit(ch)) {\n                break;\n            }\n            position++;\n        }\n    }\n\n    private JsonValue readConstant(String expected, JsonValue result) {\n        if (text.regionMatches(position, expected, 0, expected.length())) {\n            position += expected.length();\n            return result;\n        }\n        throw new IllegalArgumentException(\"Unable to read json constant for: \" + expected);\n    }\n\n    /**\n     * ws\n     * |---- \"\"\n     * |---- '0020' ws\n     * |---- '000A' ws\n     * |---- '000D' ws\n     * |---- '0009' ws\n     */\n    private void ignoreWhitespace() {\n        while (position < length) {\n            final int ch = peekChar();\n            switch (ch) {\n                case ' ': // '0020' SPACE\n                case '\\n': // '000A' LINE FEED\n                case '\\r': // '000D' CARRIAGE RETURN\n                case '\\t': // '0009' CHARACTER TABULATION","sourceCodeStart":291,"sourceCodeEnd":327,"githubUrl":"https://github.com/quarkusio/quarkus/blob/e1c734241f34c7919086ceb4c9262b4a58f6de44/independent-projects/bootstrap/json/src/main/java/io/quarkus/bootstrap/json/JsonReader.java#L291-L327","documentation":"readConstant() parses JSON literals true, false, and null by exact region match. If the text at the current position does not exactly equal the expected literal (e.g. 'tru', 'True', 'nullx'), the literal is malformed and IllegalArgumentException is thrown. It enforces JSON's case-sensitive lowercase literal spelling.","triggerScenarios":"Input contains a misspelled or wrongly-cased literal where a JSON constant is expected: 'True', 'TRUE', 'None', 'tru e', or a literal immediately followed by extra characters, e.g. 'nullx'.","commonSituations":"Generating JSON from another language's literals (Python True/None, JavaScript undefined); template/serialization bugs appending stray characters after literals; hand-written JSON with capitalized booleans.","solutions":["Replace the literal with the exact lowercase JSON form: true, false, or null","Fix the producer to serialize language-native booleans/nulls to JSON correctly (e.g. Python's json module instead of str(True))","Check for stray characters right after the literal and remove them"],"exampleFix":"// before\n{\"flag\":True, \"value\":None}\n// after\n{\"flag\":true, \"value\":null}","handlingStrategy":"validation","validationCode":"// Pre-check for non-lowercase JSON literals before parsing\nif (jsonText.matches(\"(?s).*(True|FALSE|None|NULL|undefined).*\")) {\n    throw new IllegalArgumentException(\"Non-JSON literal found (use true/false/null)\");\n}","typeGuard":null,"tryCatchPattern":"try {\n    JsonValue v = new JsonReader(text).read();\n} catch (IllegalArgumentException e) {\n    if (e.getMessage().startsWith(\"Unable to read json constant\")) {\n        // identify and correct the malformed literal reported in the message\n    }\n}","preventionTips":["JSON literals are lowercase only: true, false, null — never True/None/NULL","Use a proper JSON serializer when converting from Python/JS values","Watch for stray characters appended directly after literals (e.g. 'nullx')"],"tags":["json","parser","literals"],"backgroundTag":"malformed-json-input","analyzedSha":"e1c734241f34c7919086ceb4c9262b4a58f6de44","analyzedAt":"2026-09-05T17:01:29.979Z","contentChangedAt":"2026-09-05T17:01:29.979Z","schemaVersion":2},"datasetVersion":"2026-09-14T00:17:10.932Z"}