Skip to content

JavaScript · browsers and Node.js

Unexpected number in JSON at position N

Current Chrome and Node.js throw Unexpected number when a JSON number has a leading zero, such as 02139; older versions also used it for a number where a comma belonged.

Updated · 2 min read

console
Chrome, Edge, Node.jsSyntaxError: Unexpected number in JSON at position 40 (line 3 column 11)
Node.js 18 and 20, older ChromeSyntaxError: Unexpected number in JSON at position 40
FirefoxSyntaxError: JSON.parse: expected ',' or '}' after property value in object at line 3 column 11 of the JSON data
SafariSyntaxError: JSON Parse error: Expected '}'

Find it in your JSON

Paste the text that failed. The checker points at the exact spot, and Repair fixes most syntax mistakes.

Input · JSON

Invalid JSON

Line 3, column 10

Number 02139 has a leading zero.

1{2  "customer": "Lena Ortiz",3  "zip": 02139,          ^4  "plan": "team"

Fix: JSON numbers cannot start with 0 unless they are 0 or a decimal like 0.5. Remove the zero or quote the value as a string.

Why this happens
Invalid JSONRuns in your browser

Load from a URL

Your browser fetches it directly, so the server must allow cross-origin requests (CORS).

Why it happens

A JSON number cannot start with 0 unless it is 0 itself or a decimal like 0.5. Chrome and Node.js read the 0 of 02139, find another digit and stop: position 40 is the 2. Most common sources first:

1. Codes that look like numbers. ZIP codes, employee and product IDs, account numbers and PINs keep their leading zeros, and end up written without quotes.

2. Date and time parts. {"year": 2026, "month": 08} fails on the 8. A value padded with padStart(2, '0') and then pasted into a JSON template causes it.

3. Templates that insert raw values. `{"zip": ${zip}}` writes 02139 without quotes, even when zip is a string.

Firefox, Safari, Python and Go read the 0 as a finished number and then complain about the next digit, so they report a missing comma instead, as the messages above show.

The older meaning: a value where a comma belongs

Node.js 18 and older Chrome said Unexpected number for any number in the wrong place, and Unexpected string for any misplaced string:

JSON.parse('[1 2]');             // Node.js 18: Unexpected number in JSON at position 3
JSON.parse('{"a": 1 "b": 2}');   // Node.js 18: Unexpected string in JSON at position 8

Both are missing commas. Current versions report them as Expected ',' or ']' after array element and Expected ‘,’ or ‘}’ after property value.

How to fix unexpected number in JSON

Quote values that are codes

{
  "customer": "Lena Ortiz",
  "zip": "02139",
  "plan": "team"
}

If you would never do arithmetic on it, store it as a string. Drop the zero only for real quantities: "month": 8.

Build JSON with a serializer

const zip = '02139';
JSON.stringify({ zip });   // {"zip":"02139"}

json.dumps({"zip": "02139"}) gives the same in Python. Converting to a number first loses the zero: Number('02139') is 2139.

Repair

The JSON validator names the value: Number 02139 has a leading zero. JSON Repair quotes such numbers, so 02139 becomes "02139" and keeps its zero.

Same error in other languages

  • Python: json.decoder.JSONDecodeError: Expecting ',' delimiter: line 3 column 11 (char 40). A lone 01 gives Extra data instead.
  • Go: invalid character '2' after object key:value pair
  • PHP: json_last_error_msg() returns Syntax error.

Other numbers JSON rejects (+5, .5, 5., hex) are listed in common JSON errors.

Questions

Is 0 on its own valid JSON?

Yes. 0, -0, 0.5 and 0e3 all parse. Only a digit straight after a leading zero is rejected.

Can an ID lose digits without a leading zero?

Yes. JSON.parse stores numbers as doubles, so 12345678901234567890 comes back as 12345678901234567000. Send long IDs as strings too; the validator warns about these numbers.

Related errors

All common JSON errors

Esc