JSON Validator
JSON Validator
How the JSON Validator works
Last updated: November 2026A JSON validator checks whether a JSON string follows the JSON specification (RFC 8259). It reports the exact line and column of any syntax error, so you can find and fix problems quickly.
The most common JSON errors a validator catches:
- Trailing commas —
["a", "b",]is invalid JSON - Single-quoted strings — JSON requires double quotes
- Comments —
// ...and/* ... */are not valid JSON - Unquoted keys — keys must always be double-quoted strings
- Mismatched brackets — every
{needs a}
All processing runs entirely in your browser via the native JSON.parse() function — your data never leaves your machine.
Common JSON Validation Errors
These are the errors developers hit most often. Each one is a syntax violation that JSON.parse() will reject.
| Error | Invalid example | Fix |
|---|---|---|
| Trailing comma | {"a":1,} | {"a":1} |
| Single quotes | {'key':'val'} | {"key":"val"} |
| Unquoted keys | {key: "value"} | {"key": "value"} |
| Comments | // comment | Remove entirely — JSON has no comment syntax |
| Unescaped newline | "line1 line2" | "line1\nline2" |
| Missing comma | {"a":1 "b":2} | {"a":1,"b":2} |
Tips & Tricks
Error position is approximate
JSON.parse() reports the character after the problem, not the problem itself. A "position 15" error often means the actual mistake is at position 14 or earlier.
Valid JSON ≠ correct data
A document can be syntactically valid JSON but semantically wrong — wrong types, missing required fields, values out of range. Use JSON Schema (Ajv, jsonschema) to enforce structure.
Numbers lose precision above 2⁵³
JavaScript numbers are IEEE 754 doubles. Integers larger than 2⁵³−1 (9007199254740991) cannot be represented exactly — use string IDs for large database IDs in APIs.
Duplicate keys are "valid" but dangerous
The JSON spec does not forbid duplicate keys — but parsers disagree on which value wins. Use the JSON Formatter's "Find Duplicates" feature to detect them.
JSON has only 7 value types
string, number, boolean (true/false), null, object, array — and nothing else. No dates, no undefined, no regex. Dates are always strings; undefined serialises to nothing.
BOM breaks JSON parsers
A UTF-8 BOM (EF BB BF) at the start of a file causes "Unexpected token" errors in many parsers. If copy-pasted from Excel or Windows Notepad, strip the BOM before validating.
Validate JSON Programmatically
Node.js
try {
JSON.parse(input);
console.log('valid');
} catch (e) {
console.error(e.message); // includes position
} Python
import json
try:
json.loads(text)
print("valid")
except json.JSONDecodeError as e:
print(f"Line {e.lineno}, col {e.colno}: {e.msg}") CLI
# Node.js one-liner
node -e "try{JSON.parse(require('fs').readFileSync('f.json','utf8'));console.log('valid')}catch(e){console.error(e.message)}"
# Python one-liner
python3 -c "import json,sys; json.load(open(sys.argv[1])); print('valid')" data.json
# jq — exits non-zero on invalid JSON
jq . data.json > /dev/null && echo valid || echo invalid Frequently Asked Questions
What is a JSON validator?
- A JSON validator checks whether a JSON string follows the JSON specification (RFC 8259) — correct syntax, properly quoted strings, no trailing commas, no comments, and a single root value. It reports the exact line and column of any syntax error.
What are the most common JSON validation errors?
- Trailing commas after the last item, single-quoted strings (JSON requires double quotes), unquoted keys, comments (JSON has no comment syntax), and missing or extra braces or brackets.
Is my JSON data sent to a server?
- No. All validation runs entirely in your browser using the native
JSON.parse()function. Your data never leaves your machine. What is the difference between JSON lint and JSON validation?
- JSON lint and JSON validation mean the same thing for basic syntax checking — both verify that a JSON string is well-formed according to RFC 8259. The term "validation" is sometimes extended to include JSON Schema validation, which checks that values match a schema. Linting always means syntax checking only.
What is JSON Schema validation?
- JSON Schema validation additionally checks that the data matches a schema — required fields, value types, minimum/maximum values, and string patterns. This tool performs syntax validation only. For schema validation, use Ajv (JavaScript) or jsonschema (Python).
How do I validate JSON in Node.js?
- Use
JSON.parse()inside a try/catch block. The thrown SyntaxError message includes the position of the first error. For CI pipelines, the npm packagejsonlintprovides structured error output with line numbers. How do I validate JSON in Python?
- Use
json.loads()inside a try/except block catchingjson.JSONDecodeError. The exception exposes.linenoand.colnofor the exact error position. Why does valid JSON sometimes fail in my application?
- The JSON may be syntactically valid but semantically wrong — missing required fields, wrong value types, or values outside allowed ranges. Check the application's schema or API documentation for data requirements beyond basic JSON syntax.
Related Tools
Other free developer tools available on DevFormatter.
JSON Formatter
Format, validate, minify, and sort JSON. Detects duplicate keys and converts to YAML.
JSON Lint
Detect syntax errors in JSON with exact line and column positions.
JSON Minifier
Strip all whitespace from JSON to reduce payload size.
XML Validator
Check XML well-formedness with exact line and column error positions.