Data Formats 2026-04-16

Fix JSON Formatting Errors & Parsing Issues

Fix JSON parse errors, unexpected token errors, trailing commas, unquoted keys, and encoding issues. Validate and format JSON with our free online tool.

json parse error json not valid unexpected token json json formatting not working

JSON parsing errors are the number one issue developers face when working with APIs, config files, and data interchange. A single misplaced comma or missing quote can break your entire application. This guide covers every common JSON error with exact fixes.

Common errors covered

  1. 1 Unexpected token in JSON (trailing commas, comments)
  2. 2 Single quotes instead of double quotes
  3. 3 Unescaped quotes inside strings
1

Unexpected token in JSON (trailing commas, comments)

Error message
SyntaxError: Unexpected token } in JSON at position 42 SyntaxError: Unexpected token / in JSON at position 0
Root cause

JSON is stricter than JavaScript: no trailing commas, no comments, no single quotes, no undefined values. If your data works in JS but not as JSON, these are the likely culprits.

Step-by-step fix

  1. 1 Paste your JSON into the JSON Formatter.
  2. 2 The error indicator highlights the exact position of the problem.
  3. 3 Remove trailing commas before } or ].
  4. 4 Remove any // or /* */ comments.
  5. 5 Replace single quotes with double quotes.
Wrong
{
  "name": "Alice",
  "age": 30,
  "active": true,
}
Correct
{
  "name": "Alice",
  "age": 30,
  "active": true
}

2

Single quotes instead of double quotes

Error message
SyntaxError: Unexpected token ' in JSON at position 1
Root cause

JSON specification (RFC 8259) requires double quotes for all strings and keys. Single quotes are a JavaScript-ism that JSON does not support.

Step-by-step fix

  1. 1 Find all single-quoted strings: keys and values.
  2. 2 Replace every ' with ".
  3. 3 Paste into the JSON Formatter to validate.
Wrong
{'name': 'Alice', 'age': 30}
Correct
{"name": "Alice", "age": 30}

3

Unescaped quotes inside strings

Error message
SyntaxError: Unexpected token A in JSON at position 15
Root cause

Double quotes inside a JSON string value must be escaped with a backslash. Unescaped quotes terminate the string prematurely, corrupting the structure.

Step-by-step fix

  1. 1 Find any double quotes inside string values.
  2. 2 Add a backslash before each inner quote: \".
  3. 3 Alternatively, use our JSON Formatter - it will pinpoint the exact position.
Wrong
{"message": "She said "hello" to me"}
Correct
{"message": "She said \"hello\" to me"}

Prevention Tips

  • Always validate JSON before sending to APIs - use our JSON Formatter.
  • Use JSON.stringify() to generate JSON from objects instead of building strings manually.
  • If you need comments in config files, use JSON5 or YAML instead of standard JSON.
  • Set your editor to highlight JSON syntax errors in real time.

Frequently Asked Questions

Why cannot JSON have comments?

JSON was designed as a pure data interchange format. Douglas Crockford deliberately excluded comments to prevent them from being used as parsing directives. If you need comments, consider JSON5 or YAML.

What is the difference between JSON and a JavaScript object?

JavaScript objects allow single quotes, trailing commas, unquoted keys, comments, and undefined values. JSON requires double quotes, no trailing commas, no comments, and only null (not undefined).

How do I convert invalid JSON to valid JSON?

Paste it into our JSON Formatter - it highlights every error with its position. Fix each issue, then click Format to validate.

Related Error Guides

Related Tools

Still stuck? Try our free tools

All tools run in your browser, no signup required.