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 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
Unexpected token in JSON (trailing commas, comments)
SyntaxError: Unexpected token } in JSON at position 42
SyntaxError: Unexpected token / in JSON at position 0
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 Paste your JSON into the JSON Formatter.
- 2 The error indicator highlights the exact position of the problem.
-
3
Remove trailing commas before
}or]. -
4
Remove any
//or/* */comments. - 5 Replace single quotes with double quotes.
{
"name": "Alice",
"age": 30,
"active": true,
}
{
"name": "Alice",
"age": 30,
"active": true
}
Single quotes instead of double quotes
SyntaxError: Unexpected token ' in JSON at position 1
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 Find all single-quoted strings: keys and values.
-
2
Replace every
'with". - 3 Paste into the JSON Formatter to validate.
{'name': 'Alice', 'age': 30}
{"name": "Alice", "age": 30}
Unescaped quotes inside strings
SyntaxError: Unexpected token A in JSON at position 15
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 Find any double quotes inside string values.
-
2
Add a backslash before each inner quote:
\". - 3 Alternatively, use our JSON Formatter - it will pinpoint the exact position.
{"message": "She said "hello" to me"}
{"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.