JSON Schema Generator and Validator
Generate a JSON Schema from a sample document, or check data against a schema you already have. Errors list the exact path and the rule that failed. Everything runs in your browser, so nothing is uploaded.
JSON input
JSON Schema
Paste a JSON sample to generate its schema.
Options
Put your data in the first box and your schema in the second. Each error shows the path, the keyword that failed and why.
How to generate or validate with JSON Schema
- Choose the task. Pick Generate a schema from a sample, or Validate data against a schema, in the options below the boxes.
- Add your JSON. To generate, paste a sample document. To validate, paste the data in the first box and the schema in the second. Press Load sample to see either one.
- Copy or download. Copy the schema or the list of errors, or save it as a file. The result updates as you type.
A schema describes the shape of your JSON. Once you have one, you can use it to validate data, to document an API and to get autocomplete in editors that support it.
Before
{"id": 1042, "email": "ava@example.com", "roles": ["editor"]}After
{
"$schema": "https://json-schema.org/draft/2020-12/schema",
"type": "object",
"properties": {
"id": {
"type": "integer"
},
"email": {
"type": "string",
"format": "email"
},
"roles": {
"type": "array",
"items": {
"type": "string"
}
}
},
"required": [
"id",
"email",
"roles"
]
}What the generator infers, and what it cannot
A sample shows what your data looks like, not what it is allowed to look like. The generator reports the first and leaves the second to you.
- Types
- Text becomes string, true and false become boolean, and null becomes null. A whole number becomes integer, a number with a decimal part or an exponent becomes number, and a mix of both becomes number.
- Required properties
- A property is required when it is present in every object the generator saw at that level. With a single sample object, that means every property. Remove the ones that are optional in your real data.
- Arrays
- The items in an array are merged into one description. If the objects in a list have different keys, the schema lists all of them and marks as required only the keys that every object has.
- Formats
- When every string in a field is a date, a date and time, an email address, a URI, a UUID or an IPv4 address, the field gets that format. Turn the option off if you want plain strings.
- What it does not guess
- Minimum and maximum values, string lengths, patterns and enumerated values depend on business rules the sample cannot show. Add them by hand where they matter.
- Strict mode
- Tick Disallow extra properties to add additionalProperties: false to every object, so data with unknown keys fails validation.
What the validator checks
| Group | Keywords |
|---|---|
| Types and values | type, enum, const |
| Objects | properties, required, additionalProperties, patternProperties, propertyNames, minProperties, maxProperties, dependentRequired |
| Arrays | items, prefixItems, additionalItems, contains, minContains, minItems, maxItems, uniqueItems |
| Strings | minLength, maxLength, pattern, format (email, date, date-time, uri, uuid, ipv4) |
| Numbers | minimum, maximum, exclusiveMinimum, exclusiveMaximum, multipleOf |
| Combining schemas | allOf, anyOf, oneOf, not, if, then, else |
| References | $ref to #, #/definitions/... and #/$defs/... inside the same schema |
Not supported: references to other files or web addresses, $dynamicRef, unevaluatedProperties, unevaluatedItems and dependentSchemas. A schema that uses them is still checked for everything else, and those parts are ignored. Each error is one line with the path to the value, the keyword in square brackets and a plain explanation, for example $.email [format] The text is not a valid email.
The schema version only changes the $schema line. The generated keywords work in 2020-12, 2019-09 and draft-07. For draft-04 the validator also understands the older boolean form of exclusiveMinimum and exclusiveMaximum.
Why use this one
- Private by design
- Your data and your schema stay in the browser tab. Nothing is uploaded, which matters when you validate real records.
- Exact numbers
- The parser keeps numbers as written, so large IDs in the sample are not rounded before the type is chosen.
- Fix the JSON first
- If either box holds invalid JSON, you get the line and column of the problem. The auto-fix option repairs trailing commas, single quotes and comments.
- Related tools
- Validate configuration written in YAML by converting it first with YAML to JSON. Compare two versions of a document with JSON Diff, or tidy it in the JSON Formatter.
Frequently asked questions
How do I generate a JSON Schema from JSON?
Choose Generate a schema from a sample, then paste a sample document. The schema appears straight away. Pick the schema version and press Copy or Download .json. Review it, because a sample cannot show which values are optional or what ranges are allowed.
Why is every property required in the generated schema?
Because every property in your sample is present. The generator marks a property as required when it appears in every object it saw. Untick the required option, or delete the properties that can be missing in real data.
Which schema version should I choose?
2020-12 is the newest. Draft-07 is the version most tools and libraries support, so choose it if you are unsure. The generated keywords work in all of the first three, and only the $schema line changes. Draft-04 is older and is mainly for tools that still require it.
How do I validate JSON against a schema?
Choose Validate data against a schema, paste your data in the first box and the schema in the second. If the data is valid you see a confirmation. If not, each error is listed with the path, the keyword that failed and an explanation.
Which keywords does the validator support?
Types, enum and const, object, array, string and number rules, the combining keywords allOf, anyOf, oneOf, not and if/then/else, and references inside the same schema. The table on this page lists every keyword. References to other files or URLs are not followed.
How does it decide between integer and number?
By how the value is written. A whole number such as 5 is an integer. A value such as 5.0 or 1e3 is a number. If a field holds both kinds across your sample, it becomes number, because an integer is also a valid number.
Is my data uploaded to a server?
No. The schema is generated and the validation runs in your browser, and nothing is sent anywhere.
Can I validate YAML against a schema?
Convert the YAML to JSON first with the YAML to JSON tool on this site, then paste the result here as the data.
What does format validation do?
When the schema gives a field a format such as email or date-time, the validator checks the text against it. It supports email, date, date-time, uri, uuid and ipv4. You can switch the check off with the formats option, because the JSON Schema specification treats formats as optional.