{"record":{"id":"832864d079362afe","repo":"hibernate/hibernate-orm","slug":"unexpected-end-of-json-in-current-processing","errorCode":null,"errorMessage":"unexpected end of JSON [{}] in current processing state {}","messagePattern":"unexpected end of JSON \\[(.+?)\\] in current processing state (.+?)","errorType":"exception","errorClass":"IllegalStateException","httpStatus":null,"severity":"error","filePath":"hibernate-core/src/main/java/org/hibernate/type/format/StringJsonDocumentReader.java","lineNumber":230,"sourceCode":"\t\t\t\t\t}\n\t\t\t\t\tswitch ( this.processingStates.getCurrent() ) {\n\t\t\t\t\t\tcase ARRAY:\n\t\t\t\t\t\tcase OBJECT:\n\t\t\t\t\t\t\treturn getUnquotedValueType(this.jsonString.charAt( this.jsonValueStart));\n\t\t\t\t\t\tdefault:\n\t\t\t\t\t\t\tthrow new IllegalStateException( \"unexpected read [\"+\n\t\t\t\t\t\t\t\t\t\t\t\t\t\t\tthis.jsonString.substring( this.jsonValueStart,this.jsonValueEnd )+\n\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\"] in current processing state \" +\n\t\t\t\t\t\t\t\t\t\t\t\t\t\t\tthis.processingStates.getCurrent() );\n\t\t\t\t\t}\n\t\t\t\tdefault: {\n\t\t\t\t\tthrow new IllegalStateException( \"unexpected marker [\"+\n\t\t\t\t\t\t\t\t\t\t\t\t\tmarker +\n\t\t\t\t\t\t\t\t\t\t\t\t\t\"] at position \" + this.position );\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\t\tthrow new IllegalStateException( \"unexpected end of JSON [\"+\n\t\t\t\t\t\t\t\t\t\tthis.jsonString.substring( this.jsonValueStart,this.jsonValueEnd )+\n\t\t\t\t\t\t\t\t\t\t\"] in current processing state \" +\n\t\t\t\t\t\t\t\t\t\tthis.processingStates.getCurrent() );\n\t}\n\n\t/**\n\t * Gets the type of unquoted value.\n\t * We assume that the String value follows JSON specification. I.e unquoted value that starts with 't' can't be anything else\n\t * than <code>true</code>\n\t * @param jsonValueChar the value\n\t * @return the type of the value\n\t */\n\tprivate JsonDocumentItemType getUnquotedValueType(char jsonValueChar) {\n\t\tswitch(jsonValueChar) {\n\t\t\tcase 't': {\n\t\t\t\t//true\n\t\t\t\treturn JsonDocumentItemType.BOOLEAN_VALUE;\n\t\t\t}","sourceCodeStart":212,"sourceCodeEnd":248,"githubUrl":"https://github.com/hibernate/hibernate-orm/blob/fad1729dce015f908198d57a8d80274a30f905a5/hibernate-core/src/main/java/org/hibernate/type/format/StringJsonDocumentReader.java#L212-L248","documentation":"The parse loop in next() consumed separator tokens (',' or ':') and then ran out of input without producing an item — the document ends while the parser still expects more content. The message includes the last value window and current state, e.g. 'unexpected end of JSON [] in current processing state OBJECT'. It is the signature of JSON truncated right after a comma or colon.","triggerScenarios":"Documents ending with a dangling separator: {\"a\": (ends right after the colon), {\"a\":1, (ends after the comma), [1,2, — the loop consumes SEPARATOR/KEY_VALUE_SEPARATOR via break, hasNext() then fails, and control falls out of the while loop to this throw.","commonSituations":"Truncated column values (too-narrow VARCHAR, cut transfers, partial writes); hand-built JSON strings that append ',' after the last element; manual editing that deleted the tail of the value.","solutions":["Repair the truncated value in the database so the document is complete","Fix JSON-building code to never emit trailing ',' or ':' — use StringJoiner or a real serializer","Validate completeness on write with a strict parser","Catch IllegalStateException to skip/quarantine bad rows during load or migration"],"exampleFix":"// before: hand-built JSON with trailing separator\nString json = \"{\";\nfor (Map.Entry<String,String> e : map.entrySet()) {\n    json += \"\\\"\" + e.getKey() + \"\\\":\" + quote(e.getValue()) + \",\";\n}\njson += \"}\"; // produces {\"k\":\"v\",}\n// after: StringJoiner emits correct separators\nString json = map.entrySet().stream()\n        .map(e -> \"\\\"\" + e.getKey() + \"\\\":\" + quote(e.getValue()))\n        .collect(java.util.stream.Collectors.joining(\",\", \"{\", \"}\"));","handlingStrategy":"try-catch","validationCode":"// reject documents ending in a dangling separator before storing\nstatic boolean endsClean(String json) {\n    for (int i = json.length() - 1; i >= 0; i--) {\n        char c = json.charAt(i);\n        if (Character.isWhitespace(c)) continue;\n        return c != ',' && c != ':';\n    }\n    return true;\n}","typeGuard":null,"tryCatchPattern":"try {\n    entity = session.find(MyEntity.class, id);\n} catch (IllegalStateException e) {\n    if (e.getMessage() != null && e.getMessage().startsWith(\"unexpected end of JSON\")) {\n        throw new DataQualityException(\"JSON column truncated after separator\", e);\n    }\n    throw e;\n}","preventionTips":["Build JSON with StringJoiner or a serializer - never append separators manually after the last element","Prefer jsonb/text columns sized for the payload","Round-trip (serialize then parse) generated JSON in tests to catch trailing-separator bugs"],"tags":["hibernate","json","parser","truncated-input","malformed-data"],"backgroundTag":"json-parse-error","analyzedSha":"fad1729dce015f908198d57a8d80274a30f905a5","analyzedAt":"2026-08-22T04:13:57.527Z","schemaVersion":2},"datasetVersion":"2026-08-22T09:17:25.309Z"}