{"record":{"id":"fca723ffa51ed432","repo":"zloirock/core-js","slug":"unterminated-object-at-i","errorCode":null,"errorMessage":"Unterminated object at: ${i}","messagePattern":"Unterminated object at: (.+?)","errorType":"exception","errorClass":"SyntaxError","httpStatus":null,"severity":"error","filePath":"packages/core-js/modules/es.json.parse.js","lineNumber":162,"sourceCode":"      i = result.end;\n      i = this.until([':'], i) + 1;\n      // Parsing value\n      i = this.skip(IS_WHITESPACE, i);\n      result = this.fork(i).parse();\n      createProperty(nodes, key, result);\n      createProperty(object, key, result.value);\n      i = this.until([',', '}'], result.end);\n      var chr = at(source, i);\n      if (chr === ',') {\n        expectKeypair = true;\n        i++;\n      } else if (chr === '}') {\n        i++;\n        closed = true;\n        break;\n      }\n    }\n    if (!closed) throw new SyntaxError('Unterminated object at: ' + i);\n    return this.node(OBJECT, object, this.index, i, nodes);\n  },\n  array: function () {\n    var source = this.source;\n    var i = this.index + 1;\n    var expectElement = false;\n    var array = [];\n    var nodes = [];\n    var closed = false;\n    while (i < source.length) {\n      i = this.skip(IS_WHITESPACE, i);\n      if (at(source, i) === ']' && !expectElement) {\n        i++;\n        closed = true;\n        break;\n      }\n      var result = this.fork(i).parse();\n      push(nodes, result);","sourceCodeStart":144,"sourceCodeEnd":180,"githubUrl":"https://github.com/zloirock/core-js/blob/84e45fba098dd3a177d5cf2247d06ab8e98d3790/packages/core-js/modules/es.json.parse.js#L144-L180","documentation":"Thrown by the object() parser of the core-js JSON.parse polyfill when it reaches the end of the input while scanning an object without finding the closing '}'. The object was opened but never terminated, so the JSON is incomplete.","triggerScenarios":"JSON.parse() with input like '{\"a\":1' or '{' — the string ends (or a nested construct consumed to the end) before a matching '}' appears.","commonSituations":"Truncated network responses (connection dropped, response cut by proxy/timeout); files read with a byte limit or partially written; string built by concatenation where the closing brace was omitted; copying JSON and missing the final characters.","solutions":["Check the source string: ensure it is complete and ends with the matching '}' — log its length and tail before parsing","Verify the transport: check Content-Length vs actual body size, and retry the request if the response was truncated","Fix the code that builds the JSON so every '{' has a matching '}' (build objects and use JSON.stringify instead of string concatenation)","Read files fully (no premature size cap) and confirm EOF before parsing"],"exampleFix":"// before\nlet json = '{\"a\":1';\nconst data = JSON.parse(json);\n// after\nconst obj = { a: 1 };\nconst data = JSON.parse(JSON.stringify(obj)); // always well-formed","handlingStrategy":"validation","validationCode":"function isCompleteJsonObject(s) {\n  if (typeof s !== 'string') return false;\n  const t = s.trim();\n  if (!t.startsWith('{')) return false;\n  try { JSON.parse(t); return true; } catch { return false; }\n}\nif (!isCompleteJsonObject(body)) throw new Error('incomplete JSON body');","typeGuard":"function isBalancedBraces(s) {\n  if (typeof s !== 'string') return false;\n  let depth = 0, inStr = false, esc = false;\n  for (const c of s) {\n    if (esc) { esc = false; continue; }\n    if (c === '\\\\' && inStr) { esc = true; continue; }\n    if (c === '\"') inStr = !inStr;\n    else if (!inStr) {\n      if (c === '{') depth++;\n      if (c === '}') depth--;\n      if (depth < 0) return false;\n    }\n  }\n  return depth === 0 && !inStr;\n}","tryCatchPattern":"let data;\ntry {\n  data = JSON.parse(body);\n} catch (e) {\n  if (e instanceof SyntaxError && /Unterminated object/.test(e.message)) {\n    throw new Error('Response truncated; retry the request');\n  }\n  throw e;\n}","preventionTips":["Compare received body length against Content-Length and retry on mismatch","Buffer streamed/chunked responses until fully received before parsing","Build JSON via JSON.stringify of real objects instead of manual string assembly","For files, read to EOF and check the write process completed before parsing"],"tags":["json","syntax-error","unterminated","truncated-input"],"backgroundTag":"unterminated-json","analyzedSha":"84e45fba098dd3a177d5cf2247d06ab8e98d3790","analyzedAt":"2026-08-30T20:36:10.323Z","schemaVersion":2},"datasetVersion":"2026-08-30T23:17:21.991Z"}