JSONBeautifier.io
Guide · 5 min read

How to Fix Invalid JSON

JSON syntax errors are frustrating but almost always simple to fix once you know what to look for. This guide covers the 8 most common reasons JSON fails to parse, with exact before/after examples for each one and a free validator to find errors instantly.

Invalid JSON (3 errors)
Fixed JSON
{
  'name': 'Alice',
  age: 30,
  "city": "New York",
}

Step 1 — Find the Error Line

Before fixing, you need to know where the error is. Paste your JSON into the JSON Validator — it reports the exact line and character position of the first syntax error.

Note: JSON parsers stop at the first error. Fix one error, re-validate, and repeat until the document is clean. There may be multiple errors hidden behind the first one.

The 8 Most Common JSON Errors

These errors account for over 95% of all JSON validation failures:

1Single quotes instead of double quotes

JSON requires double quotes for all strings and keys. Single quotes are valid JavaScript but not valid JSON.

✕ Invalid
{'name': 'Alice'}
✓ Valid
{"name": "Alice"}
2Trailing comma after last item

Remove the comma after the last item in an object or array. Most editors can detect this with a JSON linter.

✕ Invalid
{"a": 1, "b": 2,}
✓ Valid
{"a": 1, "b": 2}
3Unquoted keys

Every key in a JSON object must be wrapped in double quotes. JavaScript objects allow unquoted keys — JSON does not.

✕ Invalid
{name: "Alice", age: 30}
✓ Valid
{"name": "Alice", "age": 30}
4Comments in JSON

JSON does not support comments of any kind — neither // nor /* */. Remove all comments before parsing.

✕ Invalid
{"key": "value" // a comment}
✓ Valid
{"key": "value"}
5Undefined or NaN values

JSON has no undefined or NaN. Replace them with null, or omit the key entirely if the value is not applicable.

✕ Invalid
{"score": NaN, "result": undefined}
✓ Valid
{"score": null, "result": null}
6Missing comma between items

Each key-value pair in an object and each element in an array must be separated by a comma.

✕ Invalid
{"a": 1 "b": 2}
✓ Valid
{"a": 1, "b": 2}
7Mismatched brackets or braces

Every opening bracket [ and brace { must have a matching closing bracket ] and brace }. Use a beautifier to reveal the nesting structure.

✕ Invalid
{"users": [{"id": 1}
✓ Valid
{"users": [{"id": 1}]}
8Numbers as strings (or vice versa)

Numbers should be unquoted (42) and strings should be quoted ("99"). Mixing them causes type errors in most parsers.

✕ Invalid
{"count": "42", "label": 99}
✓ Valid
{"count": 42, "label": "99"}

Tips to Prevent JSON Errors

Use a JSON-aware editor: VS Code, JetBrains IDEs, and Sublime Text all highlight JSON errors as you type. Enable JSON language support for your files.
Validate before committing: Add a JSON lint step to your CI pipeline (e.g. jq . file.json) to catch errors before they reach production.
Use JSON.stringify() to generate JSON: Never build JSON strings manually with string concatenation. Always use JSON.stringify() in JavaScript to guarantee valid output.
Watch for copy-paste from JavaScript: JavaScript object literals look like JSON but are not. Single-quoted strings and unquoted keys are valid JS but invalid JSON.

Validate and Fix Your JSON Now

Paste your JSON and get the exact error line instantly — free, no sign-up.

Open JSON Validator

Related Guides