{"record":{"id":"edba8d10f0467427","repo":"zloirock/core-js","slug":"failed-to-parse-value-at-index","errorCode":null,"errorMessage":"Failed to parse value at: ${index}","messagePattern":"Failed to parse value at: (.+?)","errorType":"exception","errorClass":"SyntaxError","httpStatus":null,"severity":"error","filePath":"packages/core-js/modules/es.json.parse.js","lineNumber":226,"sourceCode":"    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;\n    if (slice(this.source, index, endIndex) !== keyword) throw new SyntaxError('Failed to parse value at: ' + index);\n    return this.node(PRIMITIVE, value, index, endIndex);\n  },\n  skip: function (regex, i) {\n    var source = this.source;\n    for (; i < source.length; i++) if (!exec(regex, at(source, i))) break;\n    return i;\n  },\n  until: function (array, i) {\n    i = this.skip(IS_WHITESPACE, i);\n    var chr = at(this.source, i);\n    for (var j = 0; j < array.length; j++) if (array[j] === chr) return i;\n    throw new SyntaxError('Unexpected character: \"' + chr + '\" at: ' + i);\n  }\n};\n\nvar NO_SOURCE_SUPPORT = fails(function () {\n  var unsafeInt = '9007199254740993';\n  var source;","sourceCodeStart":208,"sourceCodeEnd":244,"githubUrl":"https://github.com/zloirock/core-js/blob/84e45fba098dd3a177d5cf2247d06ab8e98d3790/packages/core-js/modules/es.json.parse.js#L208-L244","documentation":"This SyntaxError is thrown by core-js's polyfilled JSON.parse when a value is expected at the current index but the text there does not match any valid JSON value start (number, string, true, false, null, '{', '['). The keyword() helper throws it when a literal such as 'true', 'false' or 'null' is expected at the index but the slice of the source differs from that keyword.","triggerScenarios":"JSON.parse on text with a misspelled or wrongly-cased literal (True, FALSE, nul, nil), an unexpected token where a value should be (',,' leading/trailing commas, unquoted words like undefined), or input that ends prematurely right where a literal was expected.","commonSituations":"JavaScript objects serialized with string concatenation turning undefined into the literal text 'undefined'; data coming from other languages (Python True/None) pasted into JSON; hand-written configs; polyfilled JSON.parse on old engines where these cases occur.","solutions":["Correct the literal spelling/case to exact JSON literals: true, false, null","Remove or quote non-JSON tokens like undefined (use null instead) before parsing","Generate JSON with JSON.stringify rather than manual concatenation so undefined/bad values become valid JSON","Check the index in the message to locate the offending token in the input string","Wrap JSON.parse in try/catch and fall back to a default value or re-request the data"],"exampleFix":"// before\nJSON.parse('{\"ok\": True}'); // SyntaxError: Failed to parse value at: 7\n// after\nJSON.parse('{\"ok\": true}');","handlingStrategy":"try-catch","validationCode":"// reject non-JSON literals before parsing\ndocument ToJson(v) { return v === undefined ? null : v; }\nif (/\\b(True|False|None|NIL|undefined)\\b/.test(input)) {\n  throw new Error('Input contains non-JSON literals');\n}","typeGuard":null,"tryCatchPattern":"try {\n  return JSON.parse(input);\n} catch (e) {\n  if (e instanceof SyntaxError && /Failed to parse value/.test(e.message)) {\n    // malformed literal/token; fall back to default or re-fetch\n    return fallbackValue;\n  }\n  throw e;\n}","preventionTips":["Use exact lowercase JSON literals: true, false, null","Convert language-specific literals (Python True/None) to JSON at serialization boundaries","Never serialize undefined into payloads; map it to null or omit the key","Generate all JSON with JSON.stringify, not concatenation"],"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"}