{"record":{"id":"4437a87c2dc3e40a","repo":"karatelabs/karate","slug":"expected-or-in-object","errorCode":null,"errorMessage":"Expected ',' or '}' in object","messagePattern":"Expected ',' or '\\}' in object","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"karate-js/src/main/java/io/karatelabs/js/JsonParser.java","lineNumber":143,"sourceCode":"                // 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) == '['\n            pos++;\n            List<Object> list = new ArrayList<>();\n            skipWs();\n            if (pos < len && s.charAt(pos) == ']') {\n                pos++;\n                return list;\n            }\n            while (true) {\n                skipWs();\n                list.add(parseValue());\n                skipWs();\n                if (pos >= len) {\n                    throw syntaxError(\"Unexpected end of JSON input in array\");","sourceCodeStart":125,"sourceCodeEnd":161,"githubUrl":"https://github.com/karatelabs/karate/blob/a22eb90246d958d15a47bf436693d0121ad2812d/karate-js/src/main/java/io/karatelabs/js/JsonParser.java#L125-L161","documentation":"Thrown by JsonParser.parseObject when, after a complete key/value pair, the next non-whitespace character is neither ',' (next pair) nor '}' (end of object). The input is structurally malformed inside an object — e.g. two values separated by something other than a comma. RFC 8259 allows only ',' or '}' at that position, so the parser fails fast.","triggerScenarios":"Parsing input like '{\"a\":1 \"b\":2}' (missing comma between pairs) or '{\"a\":1 b}' — a stray character appears where ',' or '}' is required.","commonSituations":"Hand-edited JSON with a missing comma between properties, concatenating two JSON objects without a comma, generating JSON by naive string concatenation, accidentally pasting text inside a JSON object.","solutions":["Look at the character position reported by the error and insert the missing ',' between the object's members.","Remove any stray characters after the last valid key/value pair.","Build JSON via structured serialization (map building, a JSON library) instead of string concatenation.","Lint the JSON with a standard tool before parsing to catch the malformed pair early."],"exampleFix":"// before\n'{\"a\": 1 \"b\": 2}'\n// after\n'{\"a\": 1, \"b\": 2}'","handlingStrategy":"validation","validationCode":"// Reject objects with missing commas: parse with a standard parser first\ntry {\n    new com.fasterxml.jackson.databind.ObjectMapper().readTree(json);\n} catch (JsonProcessingException e) {\n    throw new IllegalArgumentException(\"JSON object separators invalid: \" + e.getOriginalMessage());\n}","typeGuard":"static boolean hasBalancedObjectSyntax(String s) {\n    return s != null && s.trim().matches(\"\\\\{.*\\}\");\n} // plus a real parse check before trusting it","tryCatchPattern":"try {\n    Object o = Json.parse(raw);\n} catch (JsonSyntaxException e) {\n    int pos = e.getPosition();\n    throw new IllegalArgumentException(\"Bad JSON near offset \" + pos + \": expected ',' or '}'\");\n}","preventionTips":["Use IDE JSON validation/formatting when hand-editing JSON files.","Generate JSON with map builders or serializers, never manual strings.","Add a schema/format check step before parsing user-supplied JSON.","When merging JSON objects, use a library merge, not string concatenation."],"tags":["json","syntax-error","missing-comma"],"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"}