{"record":{"id":"a415bcf781de0901","repo":"karatelabs/karate","slug":"expected-after-object-key","errorCode":null,"errorMessage":"Expected ':' after object key","messagePattern":"Expected ':' after object key","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"karate-js/src/main/java/io/karatelabs/js/JsonParser.java","lineNumber":120,"sourceCode":"\n        private Map<String, Object> parseObject() {\n            // we know s.charAt(pos) == '{'\n            pos++;\n            Map<String, Object> map = new LinkedHashMap<>();\n            skipWs();\n            if (pos < len && s.charAt(pos) == '}') {\n                pos++;\n                return map;\n            }\n            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                }","sourceCodeStart":102,"sourceCodeEnd":138,"githubUrl":"https://github.com/karatelabs/karate/blob/a22eb90246d958d15a47bf436693d0121ad2812d/karate-js/src/main/java/io/karatelabs/js/JsonParser.java#L102-L138","documentation":"After reading an object key, parseObject requires a `:` separator before the value. Missing separators, stray characters (e.g. `=` as in JS `var x = {...}` fragments), or a truncated key/value pair cause \"Expected ':' after object key\".","triggerScenarios":"Parsing `{\"a\" 1}`, `{\"a\" = 1}`, or input where whitespace/newline corruption removed the colon between key and value; nested parseValue calls then re-enter parseObject and fail at the separator check.","commonSituations":"Editing JSON by hand and deleting a colon; string manipulation that splits/mangles key-value pairs; generating JSON via string concatenation instead of a serializer.","solutions":["Insert the missing `:` between key and value in the JSON text.","Generate JSON programmatically (serializer/library) instead of string concatenation.","Check for characters like `=` or `=>` that replaced the colon and fix them."],"exampleFix":"// before\nvar x = JSON.parse('{\"a\" 1}');\n\n// after\nvar x = JSON.parse('{\"a\": 1}');","handlingStrategy":"validation","validationCode":"// detect missing colon between key and value: \"key\" followed by non-colon\nif (/\"\\s*[^\\s:]\\s*[,}\\d]/.test(input) && !/\"\\s*:/.test(input)) {\n    throw new IllegalArgumentException('each key needs a colon before its value');\n}","typeGuard":null,"tryCatchPattern":"try {\n    var obj = JSON.parse(input);\n} catch (e) {\n    if (('' + e).indexOf(\"Expected ':' after object key\") >= 0) {\n        console.log('a colon is missing between a key and its value');\n    }\n    throw e;\n}","preventionTips":["Build JSON with a serializer instead of string concatenation.","After editing JSON by hand, re-check every `key value` pair for its colon.","Use an editor with JSON syntax highlighting to catch missing separators."],"tags":["json","parser","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-16T19:17:19.609Z"}