zloirock/core-js · error · SyntaxError

Failed to parse value at: ${index}

Error message

Failed to parse value at: ${index}

What it means

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.

Source

Thrown at packages/core-js/modules/es.json.parse.js:226

    if (at(source, i) === '.') {
      var fractionStartIndex = i + 1;
      i = this.skip(IS_DIGIT, fractionStartIndex);
      if (fractionStartIndex === i) throw new SyntaxError("Failed to parse number's fraction at: " + i);
    }
    if (at(source, i) === 'e' || at(source, i) === 'E') {
      i++;
      if (at(source, i) === '+' || at(source, i) === '-') i++;
      var exponentStartIndex = i;
      i = this.skip(IS_DIGIT, i);
      if (exponentStartIndex === i) throw new SyntaxError("Failed to parse number's exponent value at: " + i);
    }
    return this.node(PRIMITIVE, Number(slice(source, startIndex, i)), startIndex, i);
  },
  keyword: function (value) {
    var keyword = '' + value;
    var index = this.index;
    var endIndex = index + keyword.length;
    if (slice(this.source, index, endIndex) !== keyword) throw new SyntaxError('Failed to parse value at: ' + index);
    return this.node(PRIMITIVE, value, index, endIndex);
  },
  skip: function (regex, i) {
    var source = this.source;
    for (; i < source.length; i++) if (!exec(regex, at(source, i))) break;
    return i;
  },
  until: function (array, i) {
    i = this.skip(IS_WHITESPACE, i);
    var chr = at(this.source, i);
    for (var j = 0; j < array.length; j++) if (array[j] === chr) return i;
    throw new SyntaxError('Unexpected character: "' + chr + '" at: ' + i);
  }
};

var NO_SOURCE_SUPPORT = fails(function () {
  var unsafeInt = '9007199254740993';
  var source;

View on GitHub (pinned to 84e45fba09)

Solutions

  1. Correct the literal spelling/case to exact JSON literals: true, false, null
  2. Remove or quote non-JSON tokens like undefined (use null instead) before parsing
  3. Generate JSON with JSON.stringify rather than manual concatenation so undefined/bad values become valid JSON
  4. Check the index in the message to locate the offending token in the input string
  5. Wrap JSON.parse in try/catch and fall back to a default value or re-request the data

Example fix

// before
JSON.parse('{"ok": True}'); // SyntaxError: Failed to parse value at: 7
// after
JSON.parse('{"ok": true}');
Defensive patterns

Strategy: try-catch

Validate before calling

// reject non-JSON literals before parsing
document ToJson(v) { return v === undefined ? null : v; }
if (/\b(True|False|None|NIL|undefined)\b/.test(input)) {
  throw new Error('Input contains non-JSON literals');
}

Try / catch

try {
  return JSON.parse(input);
} catch (e) {
  if (e instanceof SyntaxError && /Failed to parse value/.test(e.message)) {
    // malformed literal/token; fall back to default or re-fetch
    return fallbackValue;
  }
  throw e;
}

Prevention

When it happens

Trigger: 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.

Common situations: 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.

Understand the failure class

Related errors


AI-assisted analysis of zloirock/core-js@84e45fba09 (2026-08-30). Data as JSON: /api/errors/edba8d10f0467427. Report an issue: GitHub.