{"record":{"id":"7c34e889648521d4","repo":"zloirock/core-js","slug":"failed-to-parse-number-at-i","errorCode":null,"errorMessage":"Failed to parse number at: ${i}","messagePattern":"Failed to parse number at: (.+?)","errorType":"exception","errorClass":"SyntaxError","httpStatus":null,"severity":"error","filePath":"packages/core-js/modules/es.json.parse.js","lineNumber":207,"sourceCode":"        break;\n      }\n    }\n    if (!closed) throw new SyntaxError('Unterminated array at: ' + i);\n    return this.node(OBJECT, array, this.index, i, nodes);\n  },\n  string: function () {\n    var index = this.index;\n    var parsed = parseJSONString(this.source, this.index + 1);\n    return this.node(PRIMITIVE, parsed.value, index, parsed.end);\n  },\n  number: function () {\n    var source = this.source;\n    var startIndex = this.index;\n    var i = startIndex;\n    if (at(source, i) === '-') i++;\n    if (at(source, i) === '0') i++;\n    else if (exec(IS_NON_ZERO_DIGIT, at(source, i))) i = this.skip(IS_DIGIT, i + 1);\n    else throw new SyntaxError('Failed to parse number at: ' + i);\n    if (at(source, i) === '.') {\n      var fractionStartIndex = i + 1;\n      i = this.skip(IS_DIGIT, fractionStartIndex);\n      if (fractionStartIndex === i) throw new SyntaxError(\"Failed to parse number's fraction at: \" + i);\n    }\n    if (at(source, i) === 'e' || at(source, i) === 'E') {\n      i++;\n      if (at(source, i) === '+' || at(source, i) === '-') i++;\n      var exponentStartIndex = i;\n      i = this.skip(IS_DIGIT, i);\n      if (exponentStartIndex === i) throw new SyntaxError(\"Failed to parse number's exponent value at: \" + i);\n    }\n    return this.node(PRIMITIVE, Number(slice(source, startIndex, i)), startIndex, i);\n  },\n  keyword: function (value) {\n    var keyword = '' + value;\n    var index = this.index;\n    var endIndex = index + keyword.length;","sourceCodeStart":189,"sourceCodeEnd":225,"githubUrl":"https://github.com/zloirock/core-js/blob/84e45fba098dd3a177d5cf2247d06ab8e98d3790/packages/core-js/modules/es.json.parse.js#L189-L225","documentation":"This SyntaxError is thrown by core-js's polyfilled JSON.parse while parsing a JSON number token. It fires when, at the current parse position, the source does not begin with a valid JSON number: there is no optional '-', no '0', and no non-zero digit to start an integer. The library throws it because the text at that offset cannot possibly be a JSON number, so parsing must abort per the JSON grammar.","triggerScenarios":"Calling JSON.parse (routed through the core-js es.json.parse polyfill, e.g. on engines without native JSON or with the pure version) on text where a value position starts with a character that cannot begin a number, such as '+5', '.5', '01x' contexts, or a stray digit-adjacent symbol after '-' like '-.' or '- '.","commonSituations":"Parsing hand-edited config or data files where numbers were written as '.5' or '+1'; receiving truncated or corrupted JSON over the wire; building JSON strings via naive string concatenation (e.g. 'value=' + x producing invalid tokens); running on old engines where core-js replaces native JSON.parse so even slightly malformed JSON hits polyfill-specific messages.","solutions":["Validate/repair the JSON text before parsing (e.g. with a linter or a JSON schema/parser check) and ensure every number starts with a digit or '-' followed by a digit","Use JSON5 or a tolerant parser if you legitimately need '.5' or '+1' style numbers instead of forcing them through JSON.parse","If data comes from an external system, log the string and the index reported in the message to inspect the offending character","Ensure core-js is not shadowing a working native JSON.parse unnecessarily (check useBuiltPure/exports configuration); on modern engines native JSON.parse gives a clearer message","Wrap JSON.parse in try/catch and surface a user-friendly error including the failing index"],"exampleFix":"// before\nJSON.parse('{\"score\": .5}'); // SyntaxError: Failed to parse number at: 10\n// after\nJSON.parse('{\"score\": 0.5}');","handlingStrategy":"validation","validationCode":"function looksLikeJsonNumberAt(str, i) {\n  return /^-?(0|[1-9]\\d*)(\\.\\d+)?([eE][+-]?\\d+)?/.test(str.slice(i));\n}\n// before parsing: ensure every value position starts with a valid token\nif (!looksLikeJsonNumberAt(input, idx)) throw new Error('Invalid number at ' + idx);","typeGuard":"function isValidJsonNumber(s) {\n  return typeof s === 'string' && /^-?(0|[1-9]\\d*)(\\.\\d+)?([eE][+-]?\\d+)?$/.test(s.trim());\n}","tryCatchPattern":"try {\n  return JSON.parse(input);\n} catch (e) {\n  if (e instanceof SyntaxError && /Failed to parse number/.test(e.message)) {\n    throw new Error('Malformed number in JSON payload: ' + e.message);\n  }\n  throw e;\n}","preventionTips":["Never build JSON via string concatenation; always use JSON.stringify","Normalize numbers with Number(x) before serializing","Reject '.5'/'+1' style numbers at input boundaries","Run a JSON linter on hand-maintained data files","Confirm which JSON.parse implementation runs on your target engines"],"tags":["json","syntax-error","polyfill","core-js"],"backgroundTag":"invalid-json-syntax","analyzedSha":"84e45fba098dd3a177d5cf2247d06ab8e98d3790","analyzedAt":"2026-08-30T20:36:10.323Z","schemaVersion":2},"datasetVersion":"2026-08-30T23:17:21.991Z"}