zloirock/core-js · error · SyntaxError

Failed to parse number's fraction at: ${i}

Error message

Failed to parse number's fraction at: ${i}

What it means

This SyntaxError is thrown by core-js's polyfilled JSON.parse when a JSON number contains a '.' starting a fractional part, but there is no digit immediately after the dot. The JSON grammar requires at least one digit after '.', so inputs like '1.' or '0.e5' are invalid and parsing aborts at the index reported.

Source

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

    return this.node(OBJECT, array, this.index, i, nodes);
  },
  string: function () {
    var index = this.index;
    var parsed = parseJSONString(this.source, this.index + 1);
    return this.node(PRIMITIVE, parsed.value, index, parsed.end);
  },
  number: function () {
    var source = this.source;
    var startIndex = this.index;
    var i = startIndex;
    if (at(source, i) === '-') i++;
    if (at(source, i) === '0') i++;
    else if (exec(IS_NON_ZERO_DIGIT, at(source, i))) i = this.skip(IS_DIGIT, i + 1);
    else throw new SyntaxError('Failed to parse number at: ' + i);
    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) {

View on GitHub (pinned to 84e45fba09)

Solutions

  1. Fix the JSON source so every '.' in a number is followed by at least one digit ('1.' -> '1.0' or '1')
  2. If a trailing dot is intentional, use JSON5 or another lenient parser instead of JSON.parse
  3. Sanitize generated numbers before embedding: Number(x) then JSON.stringify, never manual concatenation
  4. Inspect the index in the error message to locate the malformed number in the input string
  5. Catch the SyntaxError around JSON.parse and report the raw payload for debugging

Example fix

// before
JSON.parse('{"price": 1.}'); // SyntaxError: Failed to parse number's fraction at: 11
// after
JSON.parse('{"price": 1.0}');
Defensive patterns

Strategy: validation

Validate before calling

// reject numbers with a digit-less fraction before embedding in JSON
function hasValidFraction(numStr) {
  return !/\.(?![0-9])/.test(numStr);
}

Try / catch

try {
  return JSON.parse(input);
} catch (e) {
  if (e instanceof SyntaxError && /number's fraction/.test(e.message)) {
    console.error('Truncated/dangling decimal point in JSON:', e.message);
    return null; // or re-request data
  }
  throw e;
}

Prevention

When it happens

Trigger: JSON.parse on text where a number literal has a trailing or digit-less decimal point, e.g. '{"x": 1.}', '1.,', or '2. e3'; typically produced by code generating JSON via string concatenation or by truncated numeric output (toFixed/serialization cut off).

Common situations: Truncated log or telemetry lines where the fractional digits were cut off; template-built payloads like `"price": ${price}.` ; hand-edited configs; polyfilled JSON.parse on legacy engines surfacing the malformed number.

Understand the failure class

Related errors


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