JSON.parse Keeps Failing? Every Error Explained + Fix in 10 Seconds (2026)
Bookmark this. Every common JSON.parse error listed with exact cause, invalid vs valid example, and fix. Use it when you hit JSON syntax error and need to understand it fast.

Table of Contents
How to read JSON errors
JSON.parse() throws SyntaxError on invalid JSON. Message always has 2 pieces: what went wrong, and position (character offset from start) where parser failed.
Example: SyntaxError: Unexpected token ',', ..."age": 30,}" is not valid JSON (Chrome) or SyntaxError: JSON.parse: unexpected character at line 3 column 14 (Firefox).
Wording varies by browser / engine. Chrome, Firefox, Node, Deno each phrase differently. Cause is always same. This guide covers cause + fix for every common error, whatever runtime produced message.
Fastest way to fix: paste JSON into omnikitbolt JSON Formatter. It runs JSON.parse locally and shows error + position, jump straight to problem.
Unexpected token
Error messages:
Unexpected token 'X', ..."..." is not valid JSON(Chrome)JSON Parse error: Expected 'X'(Safari)Unexpected token X in JSON at position N(Node older)
Cause: Parser hit character it did not expect at specific position. Character X in message is unexpected char. Generic error covering many cases (trailing comma, single quote, unquoted key, comment). Specific char tells you which sub-case:
| Unexpected char | Likely cause |
|---|---|
| ' | Single quote instead of double quote for key / string |
| } or ] | Trailing comma before closing bracket: {"a":1,} |
| / | Comment in JSON (// or /*) |
| letter (a-z) | Unquoted key, or invalid literal like undefined, NaN |
| second " | Missing comma between two adjacent strings / objects |
Unexpected end of JSON input
Error messages:
Unexpected end of JSON inputJSON.parse: unexpected end of data at line N column N(Firefox)SyntaxError: Unterminated string in JSON at position N
Cause: JSON string ended before parser finished reading complete value. Most common:
- Missing closing bracket. Object / array opened but never closed.
- Truncated response. API response cut off mid-stream - network error, timeout, server crash. JSON incomplete.
- Empty string.
JSON.parse("")throws this - empty string is not valid JSON. - Unterminated string. String opened with " but closing " missing.
// Invalid: missing closing brace
{"name": "Alice", "scores": [10, 20, 30]
// Valid
{"name": "Alice", "scores": [10, 20, 30]}
// Invalid: truncated string
{"name": "Ali
// Valid
{"name": "Alice"}Fix: Add missing closing bracket. If JSON from API, check full response body received before parsing. Use response.text() to inspect raw body before response.json(). Guard empty: text ? JSON.parse(text) : null.
Paste broken JSON, see exact error + position
JSON Formatter runs JSON.parse in browser and shows error with position. Fix, format, copy. No upload, no server.
Open JSON Formatter, FreeTrailing comma
Error: Unexpected token '}' or Unexpected token ']'
Cause: Comma after last item in object / array. Parser expects new item after comma but finds closing bracket.
// Invalid: trailing comma in object
{
"name": "Alice",
"age": 30,
}
// Invalid: trailing comma in array
[1, 2, 3,]
// Valid object
{
"name": "Alice",
"age": 30
}
// Valid array
[1, 2, 3]Fix: Remove comma after last item. In multi-line object, this is comma on last property line before }.
Why so common: JS (ES5+) allows trailing commas, many style guides encourage them (cleaner diffs). When devs copy JS object literal into JSON context, trailing comma follows. Fix is always remove comma.
Single quotes instead of double quotes
Error: Unexpected token '''
Cause: Single quotes used for key or string value. JSON only accepts double quotes.
// Invalid: single-quoted key and value
{'name': 'Alice'}
// Invalid: single-quoted value only
{"name": 'Alice'}
// Valid
{"name": "Alice"}Fix: Replace all single quotes with double quotes. In most editors, find-replace on ' works, but careful: if string values contain apostrophes, those are literal inside double-quoted JSON string - they do NOT need escaping in JSON since strings are delimited by double quotes.
Unquoted keys
Error: Unexpected token 'n' (or first letter of unquoted key)
Cause: Key written without quotes, like JS object literal. JSON requires all keys double-quoted strings.
// Invalid: unquoted keys
{name: "Alice", age: 30}
// Valid
{"name": "Alice", "age": 30}Fix: Add double quotes around every key. Parser sees first letter of unquoted key and does not recognize it as valid start of JSON value (would need to be ", {, [, t for true, f for false, n for null, or digit).
Comments in JSON
Error: Unexpected token '/'
Cause: // or /* */ comment in JSON. Comments not part of JSON spec.
// Invalid: line comment
{
"host": "localhost", // database host
"port": 5432
}
// Invalid: block comment
{
/* database config */
"host": "localhost"
}
// Valid: no comments
{
"host": "localhost",
"port": 5432
}Fix: Remove all comments. If you need comments in config, rename file to .jsonc (JSON with Comments) and use parser that supports it. VS Code reads settings.json as JSONC. Node does not support JSONC natively; use jsonc-parser.
undefined, NaN, and Infinity
Errors:
Unexpected token 'u'(for undefined)Unexpected token 'N'(for NaN)Unexpected token 'I'(for Infinity)
Cause: These JS values are not part of JSON spec and cannot be represented in JSON.
// Invalid
{"score": NaN, "max": Infinity, "result": undefined}
// Valid: use null for missing / non-representable
{"score": null, "max": null, "result": null}Fix: Replace with null, or number representing concept (e.g. -1 or very large number instead of Infinity). Note: JSON.stringify serializes NaN / Infinity as null, and drops undefined props entirely. Raw literals appear only if you manually write them as text.
Missing comma between items
Errors: Unexpected string, Unexpected token '"'
Cause: Two properties / array elements adjacent without comma. Parser expects comma or closing bracket after value, but finds start of new value.
// Invalid: missing comma between props
{
"name": "Alice"
"age": 30
}
// Invalid: missing comma in array
[1 2 3]
// Valid
{
"name": "Alice",
"age": 30
}
// Valid
[1, 2, 3]Fix: Add missing comma after preceding value. When you see Unexpected token "", parser reached start of new key while expecting comma / closing bracket.
Duplicate keys
Error: None from JSON.parse (see below)
Cause: Object has two props with same key. RFC 8259 says duplicate keys make object "semantically invalid" but does not require parsers to throw. Most parsers (incl. JSON.parse) silently accept and use last value.
// Technically invalid but parsed without error
{
"name": "Alice",
"name": "Bob"
}
// JSON.parse result: {"name": "Bob"} (last wins)
// Valid: distinct keys
{
"firstName": "Alice",
"lastName": "Bob"
}Why matters: Because JSON.parse does not throw, duplicate keys are silent bugs. Value you see may not be value you intended, behavior varies between parsers (some use first, some last). Linter / formatter that checks duplicates catches this when JSON.parse does not.
Mismatched / missing brackets
Errors: Unexpected token ']', Unexpected token '}', or Unexpected end of JSON input
Cause: Closing ] used to close object {, or } used to close array [. Or brackets missing / extra.
// Invalid: wrong closing type
{"scores": [10, 20, 30}]
// Invalid: extra closing
{"name": "Alice"}}
// Valid
{"scores": [10, 20, 30]}Fix: Match every { with } and every [ with ]. For complex nested JSON, formatter with syntax highlighting makes matching visible. Editor with bracket-pair colorization (VS Code built-in) helps trace deep nesting.
Unescaped control characters in strings
Error: Invalid control character at position N or Unexpected token
Cause: Raw control char (tab, newline, carriage return, or chars 0x00-0x1F) inside JSON string without escaping. JSON strings must escape these as \t, \n, \r, or \uXXXX.
// Invalid: raw newline inside string
{"message": "Line one
Line two"}
// Valid: escaped newline
{"message": "Line one\nLine two"}
// Also valid for tab
{"path": "C:\\Users\\Alice\\file.txt"}Fix: Escape control chars. Raw literal newline inside JSON string must be \n. This error often appears when JSON built by string concat / template literals instead of JSON.stringify. Always use JSON.stringify to produce JSON from JS values.
Validate JSON and see error location instantly
Paste JSON. See error with position. Fix it. Format. No upload, no account, runs entirely in browser.
Quick-fix workflow for any JSON error
Use this sequence for any JSON parse error, wherever it comes from:
- Read error char. Char X in "Unexpected token X" tells specific error type. Use table in Unexpected token section above.
- Note position. Position N (offset from zero) tells exactly where error is. Count from start, or use formatter that highlights position.
- Paste into formatter. Open omnikitbolt.com/tools/json-formatter. Paste JSON. Error + position shown immediately. Jump to that position.
- Apply fix. Find error from this guide. Correct in formatter input.
- Format again. Click Format. If multiple errors (common in manual JSON), formatter reports next error after you fix first. Repeat until JSON formats cleanly.
- Fix root cause. If JSON came from server, build script, string concat, fix generator so it produces valid JSON from start. Best fix is always
JSON.stringifyrather than manually building JSON strings.
| Error | Typical message | Fix |
|---|---|---|
| Trailing comma | Unexpected token '}' | Remove comma after last item |
| Single quotes | Unexpected token ''' | Replace all single quotes with double quotes |
| Unquoted key | Unexpected token 'n' (first letter) | Add double quotes around every key |
| Comment | Unexpected token '/' | Remove comment. Use .jsonc if needed |
| undefined / NaN | Unexpected token 'u' / 'N' | Replace with null or valid number |
| Missing comma | Unexpected string / Unexpected token '"' | Add comma after preceding value |
| Truncated JSON | Unexpected end of JSON input | Check full response received. Add missing closing bracket |
| Control char | Invalid control character | Escape as \n, \t, \r, or \uXXXX. Use JSON.stringify not string concat |
Related tools
- JSON Formatter: format, prettify, minify, validate JSON in browser. Shows error + position for every parse error. No upload, no account. See also: JSON formatting complete guide.
- URL Encode / Decode: decode percent-encoded strings, which frequently appear when JSON transmitted as URL query param. See URL encoding guide.
- Hash Generator: checksums from text / files. Useful for verifying JSON file integrity. See Hash Generator guide.
- Image to Base64: encode images as Base64 strings for embedding in JSON payloads without file upload.
Developer tools that run entirely in browser
Format JSON, encode URLs, hash files, convert images. No upload, no server, no account.
FAQ
What does 'Unexpected token' mean in JSON?
Parser hit a character it didn't expect at a specific position. Common causes: single quote instead of double (Unexpected token '), unquoted key (Unexpected token n), trailing comma (Unexpected token }), comment (Unexpected token /). Position number = character offset from start, count from zero to find exact char.
What causes 'Unexpected end of JSON input'?
JSON string ended before parser finished a complete value. Causes: missing closing } or ], truncated string (JSON cut off mid-value), or empty string passed to JSON.parse. In API context, often means response truncated by network error, Content-Length mismatch, or server error ending body early.
Can trailing commas appear in JSON arrays?
No. Trailing commas not allowed in JSON arrays or objects. [1,2,3,] is invalid. [1,2,3] is valid. Common mistake copying from JavaScript - JS (ES5+) allows trailing commas, JSON (RFC 8259) forbids them. Remove trailing comma to fix.
How do I quickly find and fix a JSON error?
Paste JSON into omnikitbolt JSON Formatter (omnikitbolt.com/tools/json-formatter). It runs JSON.parse in browser and reports error + character position. Jump to that position, identify error type (trailing comma, missing quote, single quote...), fix, format again. For large JSON, position number is critical.
Why does my JSON work in JavaScript but fail in JSON.parse?
JS object literals and JSON are not same format. JS allows unquoted keys, single quotes, trailing commas, comments, undefined, NaN, Infinity. JSON allows none. If you wrote object literal in JS and tried to use it as JSON string, it fails. Always use JSON.stringify to convert JS objects to JSON - never use raw literal as JSON string.