{"record":{"id":"ae695eb74140d6ad","repo":"antonmedv/fx","slug":"invalid-character-q-in-array","errorCode":null,"errorMessage":"Invalid character %q in array","messagePattern":"Invalid character %q in array","errorType":"panic","errorClass":null,"httpStatus":null,"severity":"error","filePath":"internal/jsonx/json.go","lineNumber":453,"sourceCode":"\t\t\t\tcontinue\n\t\t\t}\n\t\t}\n\n\t\tif p.char == ']' {\n\t\t\tcloseBracket := &Node{\n\t\t\t\tKind:       Array,\n\t\t\t\tDepth:      p.depth,\n\t\t\t\tLineNumber: p.lineNumberPlusPlus(),\n\t\t\t}\n\t\t\tcloseBracket.Value = squareBracketClose\n\t\t\tcloseBracket.Parent = arr\n\t\t\tcloseBracket.Index = -1\n\t\t\tarr.Append(closeBracket)\n\t\t\tp.next()\n\t\t\treturn arr\n\t\t}\n\n\t\tpanic(fmt.Sprintf(\"Invalid character %q in array\", p.char))\n\t}\n}\n\nfunc (p *JsonParser) parseKeyword(name string, kind Kind) *Node {\n\tstart := p.end - 1\n\tfor i := 1; i < len(name); i++ {\n\t\tp.next()\n\t\tif p.char != name[i] {\n\t\t\tpanic(fmt.Sprintf(\"Unexpected character %q in keyword\", p.char))\n\t\t}\n\t}\n\tp.next()\n\tif isEndOfValue(p.char) {\n\t\tkeyword := &Node{\n\t\t\tKind:       kind,\n\t\t\tDepth:      p.depth,\n\t\t\tValue:      string(p.data[start : p.end-1]),\n\t\t\tLineNumber: p.lineNumberPlusPlus(),","sourceCodeStart":435,"sourceCodeEnd":471,"githubUrl":"https://github.com/antonmedv/fx/blob/4f31cd3a0c5d66f1b4290a2719bab14a5cee8ebe/internal/jsonx/json.go#L435-L471","documentation":"While iterating over array elements, after each value the parser expects ',' or ']'. Any other character triggers this panic with the offending character. It enforces valid element separation in JSON arrays.","triggerScenarios":"Parsing [1 2] (missing comma), [1; 2], [1 x], or stray characters after the last element (e.g. [1]2 producing an earlier different error, [1 ,2] fine but [1 ..2] panics here).","commonSituations":"Hand-written arrays with missing commas; copy-paste from code using tuple-style syntax; corrupted numeric input like [1.2.3] where the second '.' lands between elements.","solutions":["Insert the missing comma between elements: [1 2] -> [1, 2]","Remove stray characters that are neither ',' nor ']'","Validate the document with a JSON linter to pinpoint the character","Check numbers for embedded extra dots/characters (e.g. [1.2.3] -> [1.2, 3])"],"exampleFix":"// before\n[1, 2 3]\n\n// after\n[1, 2, 3]","handlingStrategy":"validation","validationCode":"func preflightJSON(src []byte) error {\n\t// cheap structural sanity: run stdlib unmarshal into interface{} first\n\tvar v interface{}\n\tif err := json.Unmarshal(src, &v); err != nil {\n\t\treturn fmt.Errorf(\"input is not valid JSON: %w\", err)\n\t}\n\treturn nil\n}\n// call before handing data to the custom parser:\n// if err := preflightJSON(data); err != nil { skip / report }","typeGuard":null,"tryCatchPattern":"func safeParse(p *jsonx.JsonParser, data []byte) (root *jsonx.Node, err error) {\n\tdefer func() {\n\t\tif r := recover(); r != nil {\n\t\t\terr = fmt.Errorf(\"json parse failed in array: %v\", r)\n\t\t}\n\t}()\n\troot = p.Parse(data)\n\treturn\n}","preventionTips":["Validate input with encoding/json (or jq) before custom parsing","Check generated numeric strings for stray dots/characters before joining into arrays","Use serializers to build arrays; avoid manual string assembly","Log the surrounding input bytes on failure to spot corruption early"],"tags":["json","parser","syntax-error"],"backgroundTag":"invalid-json-syntax","analyzedSha":"4f31cd3a0c5d66f1b4290a2719bab14a5cee8ebe","analyzedAt":"2026-09-02T02:17:47.344Z","contentChangedAt":null,"schemaVersion":2},"datasetVersion":"2026-09-09T06:17:21.866Z"}