octobercms/october · error · Error
Broken JSON array near ${result}
Error message
Broken JSON array near ${result} What it means
Array-branch counterpart in JsonParser.parseString (October CMS AJAX framework). The scanner walks a [..] literal inserting null for empty slots on commas, and returns only on the final ']'; if input ends first, it throws with the partially built strict-JSON array in the message.
Source
Thrown at modules/system/assets/js/framework.js:2182
var body = this.getBody(str, i);
i = i + body.originLength - 1;
result += this.parseString(body.body);
type = "afterBody";
} else if (type === "afterBody") {
if (str[i] === ",") {
result += ",";
type = "needBody";
while (str[i + 1] === "," || this.isBlankChar(str[i + 1])) {
if (str[i + 1] === ",") result += "null,";
i++;
}
} else if (str[i] === "]" && i === str.length - 1) {
result += "]";
return result;
}
}
}
throw new Error("Broken JSON array near " + result);
}
}
parseKey(str, pos, quote) {
var key = "";
for (var i = pos; i < str.length; i++) {
if (quote && quote === str[i]) {
return key;
} else if (!quote && (str[i] === " " || str[i] === ":")) {
return key;
}
key += str[i];
if (str[i] === "\\" && i + 1 < str.length) {
key += str[i + 1];
i++;
}
}
throw new Error("Broken JSON syntax near " + key);
}View on GitHub (pinned to b608633a7e)
Solutions
- Add the missing ']' (count brackets: every [ needs its ])
- Repair unterminated inner strings/objects first - they can swallow the closing bracket
- Build arrays in code with JSON.stringify rather than string assembly
Example fix
<!-- before --> <div data-request-data="[10, 20">...</div> <!-- after --> <div data-request-data="[10, 20]">...</div>
Defensive patterns
Strategy: try-catch
Validate before calling
function arrayLiteralCloses(s) {
const t = s.trim();
if (t[0] !== '[') return true;
return (t.match(/\[/g) || []).length === (t.match(/\]/g) || []).length;
} Try / catch
try { const d = oc.parseJSON(raw); } catch (e) { if (/Broken JSON array near/.test(e.message)) console.error('Unterminated [ - missing closing bracket:', e.message); } Prevention
- Balance every [ with a ], including nested arrays
- Repair unterminated inner strings before blaming the brackets
- Build array attributes with JSON.stringify
When it happens
Trigger: oc.parseJSON("[1, 2") or data-request-data="[10, 20" - the closing ] never arrives; also values like [1, 'a' where the last element is left unterminated, swallowing the rest.
Common situations: Truncated array attributes from length-limited template output; hand-editing lists and deleting the closer; nested cases ([1, [2, 3]) where an inner ] is missing so the outer never closes.
Related errors
- Broken JSON object near ${result}
- Broken JSON boolean body near ${str}
- Broken JSON number body near ${body}
- Error parsing the ${name} attribute value. ${e}
- Error parsing the ${name} attribute value. ${e}
AI-assisted analysis of octobercms/october@b608633a7e (2026-08-21).
Data as JSON: /api/errors/04439a7e87c1a2e1.
Report an issue: GitHub.