How to Validate JSON
How do I validate JSON?
The fastest path is to paste the text into an online JSON validator, which parses it and points to the exact error. In code, JavaScript can run JSON.parse(text) inside a try/catch, and Python can call json.loads(text). On the command line, jq and python3 -m json.tool exit with a nonzero status when the input is invalid.
Validate in the browser
Paste your JSON into the JSON Validator and it reports a valid status or an error with the line and character. This is ideal for quick sanity checks of API responses and config snippets.
Validate in JavaScript
Run JSON.parse(text) inside a try/catch. JSON.parse throws a SyntaxError whose message includes the character position when the text is not well-formed. In Node.js you can validate a file directly: node -e "JSON.parse(require('fs').readFileSync('data.json','utf8')); console.log('valid')".
Validate in Python
json.loads(text) raises a JSONDecodeError with line and column numbers on invalid input. On the command line, python3 -m json.tool data.json prints formatted output and exits with a nonzero status for invalid JSON. Add --compact for minified output.
Validate on the command line
jq -c . data.json > /dev/null && echo valid || echo invalid prints a parse error with line and column for malformed input. The same trick validates responses piped straight from curl.
Validate before you transform
Format the JSON first to make errors visible, validate to catch problems, then convert. A missing comma is far easier to spot in pretty-printed text than in a single dense line.
Try it in your browser with our JSON Validator. No upload, no server.
Open JSON Validator →FAQ
What is the quickest way to check JSON?
Paste it into an online validator. It parses the text and reports the exact line and column of the first error.
Does JSON.parse tell me where the error is?
Yes. It throws a SyntaxError whose message includes the character position. Format the text first to map that position back to a line.
Is a tool that exits nonzero on invalid JSON useful?
Yes. It makes validation scriptable, so a CI step can fail on malformed config or test fixtures.