{"record":{"id":"04439a7e87c1a2e1","repo":"octobercms/october","slug":"broken-json-array-near-result","errorCode":null,"errorMessage":"Broken JSON array near ${result}","messagePattern":"Broken JSON array near (.+?)","errorType":"exception","errorClass":"Error","httpStatus":null,"severity":"error","filePath":"modules/system/assets/js/framework.js","lineNumber":2182,"sourceCode":"            var body = this.getBody(str, i);\n            i = i + body.originLength - 1;\n            result += this.parseString(body.body);\n            type = \"afterBody\";\n          } else if (type === \"afterBody\") {\n            if (str[i] === \",\") {\n              result += \",\";\n              type = \"needBody\";\n              while (str[i + 1] === \",\" || this.isBlankChar(str[i + 1])) {\n                if (str[i + 1] === \",\") result += \"null,\";\n                i++;\n              }\n            } else if (str[i] === \"]\" && i === str.length - 1) {\n              result += \"]\";\n              return result;\n            }\n          }\n        }\n        throw new Error(\"Broken JSON array near \" + result);\n      }\n    }\n    parseKey(str, pos, quote) {\n      var key = \"\";\n      for (var i = pos; i < str.length; i++) {\n        if (quote && quote === str[i]) {\n          return key;\n        } else if (!quote && (str[i] === \" \" || str[i] === \":\")) {\n          return key;\n        }\n        key += str[i];\n        if (str[i] === \"\\\\\" && i + 1 < str.length) {\n          key += str[i + 1];\n          i++;\n        }\n      }\n      throw new Error(\"Broken JSON syntax near \" + key);\n    }","sourceCodeStart":2164,"sourceCodeEnd":2200,"githubUrl":"https://github.com/octobercms/october/blob/b608633a7e8922487d91a8161499020121c3b3bf/modules/system/assets/js/framework.js#L2164-L2200","documentation":"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.","triggerScenarios":"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.","commonSituations":"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.","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"],"exampleFix":"<!-- before -->\n<div data-request-data=\"[10, 20\">...</div>\n\n<!-- after -->\n<div data-request-data=\"[10, 20]\">...</div>","handlingStrategy":"try-catch","validationCode":"function arrayLiteralCloses(s) {\n  const t = s.trim();\n  if (t[0] !== '[') return true;\n  return (t.match(/\\[/g) || []).length === (t.match(/\\]/g) || []).length;\n}","typeGuard":null,"tryCatchPattern":"try { const d = oc.parseJSON(raw); } catch (e) { if (/Broken JSON array near/.test(e.message)) console.error('Unterminated [ - missing closing bracket:', e.message); }","preventionTips":["Balance every [ with a ], including nested arrays","Repair unterminated inner strings before blaming the brackets","Build array attributes with JSON.stringify"],"tags":["json","parser","truncation","arrays","frontend"],"backgroundTag":"unterminated-json","analyzedSha":"b608633a7e8922487d91a8161499020121c3b3bf","analyzedAt":"2026-08-21T04:24:57.515Z","schemaVersion":2},"datasetVersion":"2026-08-21T11:28:35.574Z"}