How to validate JSON against a schema
- Paste your JSON into the editor on the left.
- In the Schema tab, paste your JSON Schema, or press Generate from JSON to start from a schema inferred from your data.
- Read the result: a green message when the JSON is valid, or a list of problems, each with its path such as $.users[0].age and the failing keyword.
Which drafts are supported?
The validator reads the $schema keyword to pick the draft: draft-04, draft-07 (also used for draft-06), 2019-09 and 2020-12. Without a $schema keyword it assumes 2020-12. The schema itself must be valid JSON.
Reading validation errors
Each problem shows the location of the failing value and the keyword that failed, for example required, type, minimum or additionalProperties, followed by a plain message. When one value breaks several rules you will see one entry per rule, so you can fix them all in one pass.
Start from a generated schema
Generate from JSON infers a schema from your data: property types, required keys (keys present in every object of an array) and array item types. It is a starting point; tighten it by adding keywords such as minLength, enum, pattern or format.
JSON Schema in five minutes
A JSON Schema is a JSON document that describes what other JSON documents must look like. The keyword type says what kind of value is allowed. For objects, properties describes each key, required lists the keys that must be present, and additionalProperties set to false rejects keys you did not list. For arrays, items describes the elements. Numbers can be limited with minimum and maximum, strings with minLength, maxLength, pattern and format, and any value can be limited to a fixed set with enum.
{
"$schema": "https://json-schema.org/draft/2020-12/schema",
"type": "object",
"required": ["id", "email"],
"properties": {
"id": { "type": "integer", "minimum": 1 },
"email": { "type": "string", "format": "email" },
"role": { "enum": ["admin", "editor", "viewer"] },
"tags": { "type": "array", "items": { "type": "string" }, "uniqueItems": true }
},
"additionalProperties": false
}Reading the error list
Every problem is shown with the location of the failing value and the keyword that failed. A required error points at the object that is missing a key, not at the key itself, because the key does not exist. A type error points at the value that has the wrong type; the most common cause is a number sent as a string. An additionalProperties error means the object contains a key your schema does not allow, which is often a typo in the key name.
When one value breaks several rules you see one entry per rule. For example, the value -3 for an age with a minimum of 0 and a type of integer fails only minimum, but the string "3" fails type and also cannot be compared for minimum, so fix the type first.
Drafts and what changed between them
The validator reads the $schema keyword to choose a draft. Draft-04 uses exclusiveMinimum and exclusiveMaximum as booleans next to minimum and maximum; draft-06 and later made them numbers. Draft-07 added if, then and else. Draft 2019-09 introduced $defs for reusable parts (older drafts used definitions) and unevaluatedProperties. Draft 2020-12 changed how tuples are written: prefixItems replaces the array form of items.
If your schema was written for one draft and behaves oddly, set $schema explicitly. Without it, 2020-12 is assumed.
Combining and reusing schemas
allOf requires a value to match every sub-schema, anyOf at least one, and oneOf exactly one. oneOf is the cause of many confusing errors, because a value that matches two branches fails it. Use $ref with $defs to reuse a definition, for example "$ref": "#/$defs/address". References to other files or URLs are not fetched by this tool, because it never makes network requests with your data; paste the referenced definitions into one schema instead.
format is a hint in the specification and validators may treat it as an annotation only. This tool checks common formats such as email, date-time, uri and uuid, but it is worth testing the formats you rely on with your production validator as well.
Using the schema elsewhere
Once a schema works here you can use it in your own code or pipeline with a validator library for your language, and in editors that understand JSON Schema to get completion and inline errors for configuration files. Start from the Generate from JSON button, which writes a first schema from your data, then tighten it by hand with the keywords above.
What is JSON?
JSON (JavaScript Object Notation) is a lightweight, text-based data format that is easy for people to read and for machines to parse. It is the de facto standard for web APIs, configuration files and data exchange between services. A JSON document is built from just six value types: objects, arrays, strings, numbers, booleans and null.
{
"name": "Ada",
"age": 36,
"admin": true,
"skills": ["math", "code"],
"address": { "city": "London" },
"manager": null
}JSON is stricter than JavaScript object literals: keys and strings must use double quotes, trailing commas are not allowed and comments are not part of the specification (RFC 8259).
Why format JSON?
APIs usually return minified JSON on a single line, which is efficient for machines but unreadable for people. Formatting (also called pretty printing or beautifying) adds consistent indentation and line breaks so that you can scan the structure, spot mistakes and review changes. Minifying does the opposite and strips whitespace to reduce size.
Frequently asked questions
Does it support $ref?
Local references inside the same schema, such as #/$defs/address, are supported. Remote references are not fetched, because the tool never makes network requests with your data.
Is format validation included?
Common formats such as email, date-time, uri and uuid are checked.
Is my JSON uploaded to a server?
No. Parsing, validation, formatting, diffing and code generation all run inside your browser, using a Web Worker. Your data is never sent to any server, which makes the tool safe for API responses, configuration files and other sensitive payloads.
Does it work offline?
Yes, after the first visit. The editor and tools are stored in your browser, so you can use them without a connection. Only the TypeScript, CSS and HTML language workers used for extra highlighting in the Code tab are downloaded the first time you use them.
How large a JSON file can I open?
Files of 20 MB and more work. Parsing happens off the main thread and the tree view is virtualized, so only the rows you can see are rendered. The editor switches to a lighter mode for very large documents.
What is the difference between formatting and minifying JSON?
Formatting (pretty printing) adds line breaks and indentation so people can read the data. Minifying removes all optional whitespace to make the payload as small as possible for network transfer or storage. Both produce identical data.
Fix common JSON errors
- Unexpected token '<' in JSON at position 0
- Unexpected end of JSON input
- Expected property name or '}' in JSON
- Trailing comma in JSON
- Expected ',' or '}' after property value in JSON
- "undefined" is not valid JSON
- Bad control character in string literal in JSON
- Unexpected non-whitespace character after JSON
- Unexpected token 'N' or an invisible character in JSON
JSON examples to try
- Simple JSON Example
- JSON Array Example
- Nested JSON Example
- User Profile JSON Example
- Paginated API Response JSON Example
- Product Catalog JSON Example
- Order and Invoice JSON Example
- Blog Posts JSON Example
- package.json Example
- GeoJSON Example
- Application Config JSON Example
- Weather API JSON Example
Cheat sheets
More JSON tools
- JSON Viewer Online
- JSON Validator
- JSON to TypeScript
- JSON to Go Struct
- JSON to Python (Pydantic)
- JSON Diff
- JSON Minifier
- JSON Pretty Print
- JSON to YAML
- JSON to CSV
- JSON to XML
- Large JSON Viewer
- JSON Tree Viewer
- JSON File Viewer
- JSON Sorter
- JSON to Zod
- JSON to Rust
- JSON to Java
- JSON to JSON Schema
- JSONPath Tester
- JSON Path Finder