{"record":{"id":"546c41eb7c3318e6","repo":"karatelabs/karate","slug":"unexpected-end-of-json-input-in-object","errorCode":null,"errorMessage":"Unexpected end of JSON input in object","messagePattern":"Unexpected end of JSON input in object","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"karate-js/src/main/java/io/karatelabs/js/JsonParser.java","lineNumber":130,"sourceCode":"            while (true) {\n                skipWs();\n                if (pos >= len || s.charAt(pos) != '\"') {\n                    throw syntaxError(\"Expected string key in object\");\n                }\n                String key = parseString();\n                skipWs();\n                if (pos >= len || s.charAt(pos) != ':') {\n                    throw syntaxError(\"Expected ':' after object key\");\n                }\n                pos++;\n                skipWs();\n                Object value = parseValue();\n                // RFC 8259: behavior of duplicate keys is unspecified; we keep\n                // the last value (matches json-smart parseKeepingOrder).\n                map.put(key, value);\n                skipWs();\n                if (pos >= len) {\n                    throw syntaxError(\"Unexpected end of JSON input in object\");\n                }\n                char c = s.charAt(pos);\n                if (c == ',') {\n                    pos++;\n                    // trailing-comma is invalid per spec: the next iteration\n                    // demands a string key, which rejects e.g. {\"a\":1,}.\n                    continue;\n                }\n                if (c == '}') {\n                    pos++;\n                    return map;\n                }\n                throw syntaxError(\"Expected ',' or '}' in object\");\n            }\n        }\n\n        private List<Object> parseArray() {\n            // we know s.charAt(pos) == '['","sourceCodeStart":112,"sourceCodeEnd":148,"githubUrl":"https://github.com/karatelabs/karate/blob/a22eb90246d958d15a47bf436693d0121ad2812d/karate-js/src/main/java/io/karatelabs/js/JsonParser.java#L112-L148","documentation":"This is a syntax error thrown by Karate's hand-written JSON parser (JsonParser.parseObject). After parsing a key/value pair, the parser skipped whitespace and reached the end of the input before seeing the ',' separator or the '}' that closes the object — meaning the JSON text stops mid-object. The library throws it because a JSON object must be closed for the parse to be well-formed per RFC 8259.","triggerScenarios":"Calling karate JSON parsing (JsonParser.parse / parseValue → parseObject) on input like '{\"a\":1' or '{\"a\":1,\"b\"' — an object whose closing '}' (or the rest of a pair after a comma) is missing before end of input.","commonSituations":"Truncated HTTP response bodies read as JSON, config/feature files cut off mid-edit, string interpolation that dropped the tail of a JSON payload, copying JSON and losing the last characters, template rendering that swallowed the closing brace.","solutions":["Print/inspect the exact JSON string being parsed and add the missing '}' (and any half-written pair) before parsing.","Validate the payload with any strict JSON linter or JSON.parse equivalent before feeding it to Karate.","If the JSON comes from an HTTP call, check status code and read the full body (don't truncate) before parsing.","If the JSON is built dynamically, fix the template/interpolation that drops the closing characters."],"exampleFix":"// before\nkarate.configure('json', '{\"name\": \"foo\"'); // truncated\n// after\nkarate.configure('json', '{\"name\": \"foo\"}');","handlingStrategy":"validation","validationCode":"// Java: validate before parsing\nstatic boolean isCompleteObject(String json) {\n    String t = json.trim();\n    return t.startsWith(\"{\") && t.endsWith(\"}\") && t.length() > 1;\n}\n// usage\nif (!isCompleteObject(payload)) throw new IllegalArgumentException(\"Truncated JSON object: \" + payload);","typeGuard":"static boolean looksLikeJsonObject(String s) {\n    if (s == null) return false;\n    String t = s.trim();\n    return t.startsWith(\"{\") && t.endsWith(\"}\");\n}","tryCatchPattern":"try {\n    Map<String, Object> map = Json.parse(payload);\n} catch (JsonSyntaxException e) {\n    log.error(\"Malformed JSON object: {}\", payload, e);\n    throw new IllegalArgumentException(\"Invalid JSON payload\", e);\n}","preventionTips":["Always validate payload completeness (HTTP status, content-length) before parsing.","Run JSON through a linter in CI for fixture/config files.","Never build JSON by string concatenation; use a serializer.","Log the raw input on parse failure to spot truncation quickly."],"tags":["json","syntax-error","parser"],"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-16T19:17:19.609Z"}