{"record":{"id":"7f162d00761aa91e","repo":"karatelabs/karate","slug":"expected-or-in-array","errorCode":null,"errorMessage":"Expected ',' or ']' in array","messagePattern":"Expected ',' or '\\]' in array","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"karate-js/src/main/java/io/karatelabs/js/JsonParser.java","lineNumber":174,"sourceCode":"            while (true) {\n                skipWs();\n                list.add(parseValue());\n                skipWs();\n                if (pos >= len) {\n                    throw syntaxError(\"Unexpected end of JSON input in array\");\n                }\n                char c = s.charAt(pos);\n                if (c == ',') {\n                    pos++;\n                    // trailing-comma rejected: the next parseValue() lands on\n                    // ']' and parseValue's default branch throws.\n                    continue;\n                }\n                if (c == ']') {\n                    pos++;\n                    return list;\n                }\n                throw syntaxError(\"Expected ',' or ']' in array\");\n            }\n        }\n\n        private String parseString() {\n            // we know s.charAt(pos) == '\"'\n            pos++;\n            StringBuilder sb = new StringBuilder();\n            while (pos < len) {\n                char c = s.charAt(pos);\n                if (c == '\"') {\n                    pos++;\n                    return sb.toString();\n                }\n                if (c == '\\\\') {\n                    pos++;\n                    if (pos >= len) {\n                        throw syntaxError(\"Unexpected end of JSON input in string escape\");\n                    }","sourceCodeStart":156,"sourceCodeEnd":192,"githubUrl":"https://github.com/karatelabs/karate/blob/a22eb90246d958d15a47bf436693d0121ad2812d/karate-js/src/main/java/io/karatelabs/js/JsonParser.java#L156-L192","documentation":"Thrown by JsonParser.parseArray when the character following a complete array element is neither ',' (next element) nor ']' (end of array). The array contains a malformed separator or stray token where the grammar only allows ',' or ']'.","triggerScenarios":"Parsing input like '[1 2]' (missing comma between elements), '[1; 2]', or '[1 }]' — an unexpected character appears between elements.","commonSituations":"Hand-written arrays missing commas, pasting values from other languages (e.g. semicolon-separated), naive string building of arrays, editing generated fixtures by hand.","solutions":["Go to the reported position and insert the missing ',' between array elements.","Remove the stray character that is not ',' or ']'.","Replace semicolons or other separators with commas.","Generate arrays programmatically with a JSON serializer rather than by hand."],"exampleFix":"// before\n'[1, 2 3]'\n// after\n'[1, 2, 3]'","handlingStrategy":"validation","validationCode":"// Pre-validate array element separators with a standard parser\ntry {\n    new com.fasterxml.jackson.databind.ObjectMapper().readTree(json);\n} catch (JsonProcessingException e) {\n    throw new IllegalArgumentException(\"Invalid array separator: \" + e.getOriginalMessage());\n}","typeGuard":"static boolean hasBalancedArraySyntax(String s) {\n    return s != null && s.trim().matches(\"\\\\[.*\\\\]\");\n} // combine with a real parse for full safety","tryCatchPattern":"try {\n    Object list = Json.parse(raw);\n} catch (JsonSyntaxException e) {\n    throw new IllegalArgumentException(\"Malformed JSON array near: \" + e.getMessage());\n}","preventionTips":["Use commas, never semicolons or spaces, between array elements.","Format JSON in an editor that flags syntax errors while typing.","Serialize arrays from code rather than writing them by hand.","Validate user-pasted JSON with JSON.parse/linter before accepting it."],"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"}