JSON Validation and Common Errors

How to validate JSON, spot parse failures, repair common mistakes, and debug malformed payloads quickly.

View
StandardDetailedCompact
Export
Copy the compact sheet, download it, or print it.
Download
`D` dense toggle · `C` copy all
## Validate JSON files
Validate with jq
jq empty input.json

# Parse a file and fail if JSON is invalid.

Validate with Python json.tool
python -m json.tool input.json

# Check syntax and pretty-print if valid.

Validate with Node.js
node -e 'JSON.parse(require("fs").readFileSync("input.json", "utf8")); console.log("valid")'

# Parse a file with JavaScript runtime tooling.

## Common parse failures
Single quotes are invalid
{ "name": "Ada" }

# Strings and keys must use double quotes.

Trailing commas are invalid
[
  1,
  2,
  3
]

# Do not leave a comma after the last item.

Object keys must be quoted
{ "enabled": true }

# Bare identifiers are invalid in JSON.

Raw newlines inside strings are invalid
{
  "text": "line 1
line 2"
}

# Use `\n` rather than an actual line break inside a string literal.

Rewrite valid JSON in normalized form
jq . broken-or-ugly.json > normalized.json

# Read and immediately re-emit clean JSON.

Recommended next

No recommendations yet.