Quick answer
A JSON validator checks that text follows the JSON grammar in RFC 8259, the rules every standard parser enforces. Paste JSON into Playxoft's free JSON Validator to check it as you type: every error is listed with its line, column and a suggested fix, and clicking one jumps to the spot. Valid JSON is also checked for duplicate keys and integers too large for JavaScript.
- Every error listed
- Line and column
- Click to jump
- Plain-English fixes
- Duplicate key warnings
- Unsafe number warnings
- Strict or lenient mode
- One-click repair
How to use the JSON Validator
- 1Paste JSON into JSON to validate, drop a file onto the editor, or click Open.
- 2Keep Strict for API payloads, or choose Lenient for JSONC config files such as
tsconfig.json. - 3Read the result: a green Valid JSON card with statistics, or a list of every error.
- 4Click an error to jump to its line and column in the editor, then fix it.
- 5Press Repair to fix common mistakes automatically, or Copy error report to share the list.
What makes JSON valid?
Valid JSON follows a short grammar defined in RFC 8259. A document holds exactly one value, and every value is one of seven things: an object, an array, a string, a number, true, false or null. The rules that trip people up:
- Strings and object keys use double quotes. Single quotes and bare keys are JavaScript, not JSON.
- Commas go between items, never after the last one.
- There are no comments of any kind.
- Numbers are plain decimals: no leading zeros (
07), no leading+, no bare.5, no hex, and noNaNorInfinity. true,falseandnullare lowercase.- Tabs and line breaks inside strings must be escaped, and the only escapes allowed are
\" \\ \/ \b \f \n \r \tand\uXXXX. - Whitespace between tokens is limited to spaces, tabs, line feeds and carriage returns.
A lone string or number is valid JSON too. The original RFC 4627 required an object or array at the top level; RFC 7159 dropped that rule in 2014 and RFC 8259 kept it that way.
Strict or lenient: which validation mode should I use?
Use Strict for anything a program will read: API requests and responses, message queues, data files and package.json. It is at least as strict as JSON.parse, Python's json module and Go's encoding/json, so if a document passes here it parses there.
Use Lenient for JSONC, the configuration dialect that adds // and /* */ comments and, in most tools, trailing commas. Lenient mode accepts those two extensions and nothing else, so single quotes and unquoted keys are still reported.
| You are checking | Mode |
|---|---|
| An API payload or webhook body | Strict |
package.json or composer.json | Strict |
tsconfig.json, VS Code settings, devcontainer.json | Lenient |
| A JavaScript object literal or JSON5 file | Repair, then Strict |
Repair converts near-JSON into strict JSON and tells you what it changed, so you can review the result before you rely on it.
Why can valid JSON still cause bugs?
Syntax is only the first check. The issues below slip past many parsers and editors, yet regularly cause production bugs, so the validator flags them as warnings:
- Duplicate keys. RFC 8259 says names should be unique but doesn't forbid duplicates, and parsers disagree on what to do.
JSON.parsekeeps the last value, other parsers keep the first or reject the document. Whichever one your code sees, the other is silently lost. - Integers beyond 2^53. JavaScript reads
9007199254740993as9007199254740992. If an ID can grow that large, send it as a string. - Numbers too large for a double, such as
1e400, whichJSON.parseturns intoInfinity. - A byte-order mark at the start of the file. RFC 8259 forbids adding one and lets parsers ignore it, but
JSON.parsethrows on it, so a file that opens fine in an editor fails in JavaScript.
I-JSON (RFC 7493), a stricter profile of JSON for internet protocols, turns the first two warnings into rules: object names must be unique, and numbers should fit an IEEE 754 double.
How do I validate JSON in code?
Every language reports syntax errors; most give you a position you can turn into a line and column:
// JavaScript: a SyntaxError whose message includes a position
try { JSON.parse(text); } catch (err) { console.error(err.message); }
# Python: JSONDecodeError has .lineno and .colno
try:
json.loads(text)
except json.JSONDecodeError as err:
print(err.lineno, err.colno, err.msg)
# jq: exit status 0 means valid
jq empty data.json
// Go: a quick yes or no, or *json.SyntaxError with an Offset
ok := json.Valid(data)All of these stop at the first error. This page keeps going and lists every error in one pass, which saves the fix, rerun, fix loop on a large file. Paste the error report into a ticket with Copy error report. Once the JSON is valid, the JSON Formatter pretty-prints, minifies or sorts it.
Is syntax validation the same as schema validation?
No. Syntax validation answers "is this JSON?". Schema validation answers "is this the JSON I expect?": the right keys, types, formats and ranges. {"age": "forty"} is perfectly valid JSON that your code may not survive.
For schema validation, describe the expected shape with JSON Schema, which validators such as Ajv check in JavaScript, or with Zod in TypeScript. The JSON to Zod generator writes a Zod schema from a sample document, so you can validate API responses at runtime with one line of code.
Frequently asked questions
Last updated by the Playxoft engineering team.