JSON Validator: How to Check if Your JSON Is Valid
Syntax validation, reading error messages, validating in code, and when you need schema validation instead.
What does it mean to validate JSON?
JSON validation — also called JSON linting — checks whether a string of text conforms to the JSON specification (RFC 8259). A valid JSON string has correct syntax: properly quoted keys and strings, no trailing commas, no comments, no undefined values, and balanced brackets. An invalid JSON string contains at least one of these errors, and any JSON parser will refuse to parse it.
Validation is not the same as checking whether your JSON contains the right data. A JSON string can be syntactically valid — parseable by any JSON parser — but still contain incorrect field names, wrong value types, or missing required keys. That second kind of check is called JSON Schema validation and is a distinct step from syntax validation. This guide covers syntax validation.
Why JSON validation matters
JSON is used everywhere — API requests and responses, configuration files, database documents, log entries, message queues, and file exports. In all these contexts, an invalid JSON string causes an immediate parse error. The downstream effect varies:
- An API receives an invalid JSON request body and returns a 400 Bad Request.
- A service reads a corrupt JSON config file and fails to start.
- A data pipeline ingests a malformed record and skips it, silently losing data.
- A frontend JavaScript call to
JSON.parse()throws an uncaught exception and crashes the page.
Validating JSON before using it — whether by pasting into a browser validator during development or running a validation step in a CI pipeline — catches these problems before they cause failures in production.
How to validate JSON in a browser
The fastest way to check JSON during development is a browser-based validator. Go to json-indent.com/validator.html and paste your JSON into the input panel. Validation runs automatically — no button to click. If the JSON is valid, the result panel shows a green "Valid JSON" status with the key/value counts. If it's invalid, the exact error line and column are highlighted in the gutter and the error message is shown in the result panel.
All validation runs in your browser — the JSON is never sent to a server, which matters when you're working with sensitive API responses or internal data.
How to validate JSON in Python
Use json.loads() inside a try/except block. If the JSON is invalid, it raises json.JSONDecodeError with the error message, line number, and column number.
import json
def validate_json(json_string):
try:
json.loads(json_string)
return True, None
except json.JSONDecodeError as e:
return False, str(e)
is_valid, error = validate_json('{"name": "Alice", "age": 30}')
print(is_valid) # True
is_valid, error = validate_json('{"name": "Alice", "age": 30,}')
print(is_valid) # False
print(error) # Trailing comma: line 1 column 30 (char 29)
You can also validate JSON files directly from the Python command line using the built-in json.tool module:
python3 -m json.tool data.json
# Outputs formatted JSON if valid, or an error message if not
How to validate JSON in JavaScript
Wrap JSON.parse() in a try/catch block. If the string is invalid JSON, it throws a SyntaxError.
function isValidJSON(str) {
try {
JSON.parse(str);
return true;
} catch (e) {
return false;
}
}
isValidJSON('{"name": "Alice"}'); // true
isValidJSON("{'name': 'Alice'}"); // false (single quotes)
isValidJSON('{"name": "Alice",}'); // false (trailing comma)
Note that JavaScript's JSON.parse is stricter than some older browsers. It correctly rejects trailing commas, comments, and other non-standard JSON extensions in all modern environments.
How to validate JSON in a shell script
For shell scripts and CI pipelines, jq is the simplest option. It exits with code 0 if the input is valid and non-zero if not:
# Validate a file
jq '.' data.json > /dev/null && echo "Valid" || echo "Invalid"
# Validate in a CI script (fail the build if invalid)
jq '.' config.json > /dev/null
If jq is not available, Python works equally well as a drop-in:
python3 -m json.tool data.json > /dev/null && echo "Valid" || echo "Invalid"
Syntax validation vs JSON Schema validation
Syntax validation checks whether a string is parseable JSON. JSON Schema validation goes further: it checks whether the parsed JSON matches an expected structure — for example, whether a user object has the required email field as a string, or whether an age value is a positive integer.
JSON Schema is a separate standard (draft-07, draft 2020-12) with libraries available in most languages: jsonschema for Python, ajv for JavaScript, and built-in validators in many API frameworks. The json-indent.com validator covers syntax only — if you need schema validation, you need a separate tool.
Validate JSON in your browser — free
Paste JSON and see the exact error line and column instantly. All validation runs in your browser — no data sent to a server.
Open JSON Validator →Frequently Asked Questions
What is the difference between JSON validation and JSON schema validation?
JSON validation (syntax validation) checks whether a string is well-formed JSON — does it follow RFC 8259? JSON Schema validation is a second step that checks whether valid JSON matches an expected structure — are the required keys present? Are the values the right types? You need syntax validation first, then schema validation if you have a schema.
How do I validate JSON in Python?
Use json.loads() inside a try/except block. If it raises json.JSONDecodeError, the JSON is invalid and the exception message includes the error position. For valid JSON, json.loads() returns the parsed Python object.
What is JSON lint?
JSON lint is another term for JSON validation — checking a JSON string for syntax errors. The term comes from the broader practice of static analysis (linting) in software development. JSON lint and JSON validator mean the same thing.
Does the validator store my JSON?
No. The json-indent.com validator runs entirely in your browser. Your JSON is never sent to any server. You can disconnect from the internet after the page loads and validation continues to work.