How to generate a JSON Schema from JSON
Three steps, about a minute.
1
Paste your JSON
Paste an API response or config file, drop a .json file onto the editor, or load the sample. The status bar validates as you type and points at the exact line of any syntax error.
2
Choose a draft and options
Pick the JSON Schema draft your validator supports, set a title and $id, and toggle required detection, formats, strict additionalProperties and examples.
3
Copy, download or validate
Copy or download the schema as JSON, YAML or TypeScript, or switch to Validate JSON to test other payloads against it before you ship.
How JSON values map to JSON Schema
The inference rules the generator applies to every value in your sample.
Which JSON Schema draft should you choose?
Pick the newest draft that every validator in your stack supports.
Getting an accurate schema
A generated schema describes the shape of your sample. These habits make it describe your real data.
✓
Paste several array items
Include two or three items that differ. Their shapes are merged, so genuinely optional keys are left out of required and mixed types become unions.
✓
Use a populated sample
Keys that are only ever null or [] produce "type": "null" or "items": {}. A response with real values gives useful types.
✓
Add business rules by hand
A sample cannot show limits. After generating, add enum, minimum, maxLength or pattern where your API enforces them, then test with the validator.
Frequently asked questions
What people usually ask about generating and validating JSON Schema.
What is a JSON Schema?
JSON Schema is a vocabulary, written in JSON, that describes the structure of a JSON document: which properties exist, what type each value has, which properties are required and what formats or ranges values must follow. It is used to validate API requests and responses, document payloads, generate forms and power editor autocompletion.
Is my JSON uploaded to a server?
No. Schema generation and validation run in your browser with JavaScript. Your JSON never leaves your device, so production payloads, tokens and customer data stay private.
Which JSON Schema draft should I use?
Use Draft-07 when you need the widest support across validators and editors. Use 2020-12 for new projects and for OpenAPI 3.1. Use Draft-04 only for older tooling such as Swagger 2.0 or validators that do not support newer drafts.
How does the generator decide which properties are required?
A property is required when it is present in every object observed at that position. For arrays of objects, all items are merged, so a key missing from any item is left optional. Turn off Mark keys as required to generate a schema without required lists.
How are null values handled?
A key that is only ever null is typed as "null". A key that is null in some samples and a string in others becomes a union type such as ["string", "null"]. Use a sample with populated values to get more useful types.
Why is a number typed as integer instead of number?
Whole numbers are typed as integer. If any value of the same key has a fractional part, the type is widened to number. In current browsers a value written as 10.0 is also recognised as a decimal. Turn off integer detection to always emit number.
Which string formats are detected?
date-time, date, uuid, email, uri and ipv4. A format is added only when every sampled value for that key matches it, and only when the selected draft defines the format: date needs Draft-07 or later and uuid needs 2019-09 or later.
Can I validate JSON against a schema?
Yes. The Validate JSON tab checks any JSON document against any schema and lists every error with its JSON Pointer path. It supports type, enum, const, numeric and string limits, pattern, format, items, prefixItems, contains, properties, patternProperties, additionalProperties, required, dependencies, allOf, anyOf, oneOf, not, if/then/else and local $ref. unevaluatedProperties, unevaluatedItems, $dynamicRef and remote $ref are not evaluated.
Can I export the schema as YAML or TypeScript?
Yes. Switch the output tab to YAML to get the same schema in YAML, for example for an OpenAPI file, or to TypeScript to get exported interfaces where optional properties are marked with ?.
Is the JSON Schema Generator free?
Yes. It is completely free, needs no sign-up, and has no limit on how many schemas you generate. Inputs up to 5 MB are supported.