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

Fast ways to check whether a document is valid JSON.

Validate with jq

Parse a file and fail if JSON is invalid.

bashANYjsonjqvalidate
bash
jq empty input.json
Notes

`jq empty` is concise and script-friendly for validation-only workflows.

Validate with Python json.tool

Check syntax and pretty-print if valid.

bashANYjsonpythonvalidate
bash
python -m json.tool input.json
Notes

A built-in option that many systems already have.

Validate with Node.js

Parse a file with JavaScript runtime tooling.

bashANYjsonnodevalidate
bash
node -e 'JSON.parse(require("fs").readFileSync("input.json", "utf8")); console.log("valid")'
Notes

Useful in JavaScript-heavy environments.

Common parse failures

The mistakes most likely to break a JSON payload.

Single quotes are invalid

Strings and keys must use double quotes.

jsonANYjsonquoteserrors
json
{ "name": "Ada" }
Notes

`{ 'name': 'Ada' }` is invalid JSON.

Trailing commas are invalid

Do not leave a comma after the last item.

jsonANYjsoncommaserrors
json
[
  1,
  2,
  3
]
Notes

`[1,2,3,]` is invalid JSON.

Object keys must be quoted

Bare identifiers are invalid in JSON.

jsonANYjsonkeyserrors
json
{ "enabled": true }
Notes

`{ enabled: true }` is valid in some JavaScript objects but not in JSON.

Raw newlines inside strings are invalid

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

jsonANYjsonstringserrors
json
{
  "text": "line 1
line 2"
}
Notes

A raw line break inside the quotes breaks parsing.

Rewrite valid JSON in normalized form

Read and immediately re-emit clean JSON.

bashANYjsonjqformat
bash
jq . broken-or-ugly.json > normalized.json
Notes

This is useful once the file parses and you want a canonical pretty form.

Recommended next

No recommendations yet.