{"record":{"id":"7b339a4f9b302d0c","repo":"can1357/oh-my-pi","slug":"expected-or-in-array","errorCode":null,"errorMessage":"Expected ',' or ']' in array","messagePattern":"Expected ',' or '\\]' in array","errorType":"exception","errorClass":"SyntaxError","httpStatus":null,"severity":"error","filePath":"packages/utils/src/json-parse.ts","lineNumber":335,"sourceCode":"\t\t\tif (c === \",\") {\n\t\t\t\tthis.#i++;\n\t\t\t\tcontinue;\n\t\t\t}\n\t\t\tconst value = this.#value(true);\n\t\t\tif (value === INCOMPLETE) return out;\n\t\t\tout.push(value);\n\t\t\tthis.#ws();\n\t\t\tconst d = this.#i < this.#n ? this.#s[this.#i] : \"\";\n\t\t\tif (d === \",\") {\n\t\t\t\tthis.#i++;\n\t\t\t\tcontinue;\n\t\t\t}\n\t\t\tif (d === \"]\") {\n\t\t\t\tthis.#i++;\n\t\t\t\treturn out;\n\t\t\t}\n\t\t\tif (this.#partial) return out;\n\t\t\tthrow new SyntaxError(\"Expected ',' or ']' in array\");\n\t\t}\n\t}\n\n\t#key(): string {\n\t\tconst c = this.#s[this.#i];\n\t\tif (c === '\"' || c === \"'\") return this.#string(this.#s.charCodeAt(this.#i));\n\t\t// Unquoted identifier key: read until a structural delimiter / whitespace.\n\t\tconst start = this.#i;\n\t\twhile (this.#i < this.#n) {\n\t\t\tconst ch = this.#s[this.#i];\n\t\t\tif (ch === \":\" || ch === \",\" || ch === \"}\" || isWhitespace(this.#s.charCodeAt(this.#i))) break;\n\t\t\tthis.#i++;\n\t\t}\n\t\tif (this.#i === start) {\n\t\t\tif (this.#partial) return \"\";\n\t\t\tthrow new SyntaxError(\"Expected object key\");\n\t\t}\n\t\treturn this.#s.slice(start, this.#i);","sourceCodeStart":317,"sourceCodeEnd":353,"githubUrl":"https://github.com/can1357/oh-my-pi/blob/969062200754ea02cfac922e5ebb8c608c079e15/packages/utils/src/json-parse.ts#L317-L353","documentation":"Thrown by RelaxedJson.#array in strict mode after an element when the next character is neither ',' nor ']' — the array elements are not properly delimited. Partial mode returns the elements parsed so far instead of throwing.","triggerScenarios":"parseJsonWithRepair with '[1 2]', '[\"a\" \"b\"]', or any non-','/']' character between elements in strict mode.","commonSituations":"An LLM emitting space-separated array items without commas; a formatting bug that dropped the delimiter when serializing; copy/paste merging two lines of an array literal.","solutions":["Insert the missing ',' or ']' at the failing position in the source","Use parseStreamingJson if the input may be an incomplete prefix","Validate the producer's serialization (e.g. always JSON.stringify arrays, never hand-build them) so delimiters cannot be dropped"],"exampleFix":"// before\nconst v = parseJsonWithRepair(`[1 2]`); // SyntaxError\n// after\nconst v = parseJsonWithRepair(`[1, 2]`); // [1, 2]","handlingStrategy":"validation","validationCode":"// Delimiter check between array elements before parsing\nconst stripped = text.replace(/\"(\\\\.|[^\"\\\\])*\"/g, '\"S\"');\nconst hasBadDelimiter = /\\S\\s+\\S/.test(stripped.replace(/[\\[\\],\\s0-9.eE+\\-]/g, \"\"));","typeGuard":null,"tryCatchPattern":"try {\n  const value = parseJsonWithRepair<T>(text);\n} catch (err) {\n  if (err instanceof SyntaxError && err.message === \"Expected ',' or ']' in array\") {\n    // fix the delimiter or reject/regenerate the payload\n  } else throw err;\n}","preventionTips":["Serialize arrays with JSON.stringify; never hand-concatenate elements","Schema-validate array arguments before use","Prompt models for strict JSON and validate output before executing tool calls"],"tags":["json","parse","array","delimiter","syntaxerror"],"backgroundTag":"json-missing-comma","analyzedSha":"969062200754ea02cfac922e5ebb8c608c079e15","analyzedAt":"2026-08-31T10:29:35.737Z","schemaVersion":2},"datasetVersion":"2026-08-31T14:17:45.589Z"}