JSON Schema Generator
Infer a JSON Schema (draft 2020-12, 2019-09 or draft-07) from sample JSON, with required keys, formats and examples.
Tool guide
What this tool does
JSON Schema Generator builds a schema from one or more example documents. It detects integers versus decimals, string formats such as date-time, email, uri and uuid, marks keys present in every sample as required, and can forbid extra properties, so you get a solid starting point for API validation or editor autocompletion.
JSON Schema is the standard way to describe what a valid JSON document looks like: which properties exist, their types, which are required and what formats strings must follow. It powers request validation in API frameworks, form generation and autocompletion in editors. Writing a schema from scratch for a large payload is tedious, though, and easy to get subtly wrong.
This tool infers a schema from real data. Every value is classified as object, array, string, integer, number, boolean or null; objects list their properties, and arrays describe their items by merging all elements. With several samples, a property that appears in all of them goes into required, and conflicting types become a type list such as ["string", "null"] or an anyOf. Strings are checked against date-time, date, time, email, uri, uuid and ipv4 patterns. The $schema keyword is set for the draft you choose, and all processing happens in your browser.
How to use JSON Schema Generator
- Paste a JSON document into Sample JSON, or open one or more .json files.
- Pick the JSON Schema version your validator supports: Draft 2020-12, Draft 2019-09 or Draft-07.
- Enter a Title, and switch on Top-level array is a list of samples if you pasted several example records in one array.
- Choose whether Required properties lists keys present in every sample, and whether to Disallow extra properties.
- Toggle Detect string formats, Use "integer" for whole numbers, Include example values and the non-empty array rule as needed.
- Copy or download schema.json, then refine descriptions, enums and ranges by hand.
Tips for better results
- Feed in several varied samples. Inference can only describe what it sees, so one example makes every key look required.
- Draft-07 is the most widely supported version in older libraries; Ajv, the most common JavaScript validator, supports 2020-12 through a dedicated class.
- Turn on Disallow extra properties for request bodies, where unexpected fields usually indicate a client bug, but leave it off for responses you consume, so new server fields do not break you.
- Formats are annotations by default in 2020-12; enable format validation in your validator if you want them enforced.
Common use cases
- Bootstrapping validation for an API endpoint from logged request bodies.
- Adding autocompletion for a custom JSON config file in an editor that reads $schema.
- Writing contract tests that fail when a third-party response changes shape.
- Documenting a data feed for partners in a machine-readable form.
Common mistakes to avoid
- Publishing an inferred schema unchanged. Add descriptions, enum values, minimum and maximum limits and pattern rules that only you know.
- Mixing drafts: a 2020-12 schema uses prefixItems and $defs, which older draft-07 validators ignore or reject.
- Expecting a null-only sample value to describe the real type. A field seen only as null is typed null until another sample shows its actual type.
Frequently asked questions
Which JSON Schema drafts are supported?
Draft 2020-12, draft 2019-09 and draft-07. The generated keywords (type, properties, required, items, format, additionalProperties) mean the same thing in all three, and only the $schema URI changes.
How are required properties decided?
A property is listed in required when it appears in every object merged at that position, for example in every item of an array. Choose None to leave all properties optional.
Why is a number typed as integer?
When every sampled value at a position is a whole number, the schema uses "integer". If any value has a fractional part the type becomes "number". You can turn integer detection off to always use number.
Is my data sent anywhere?
No. Parsing and inference run entirely in your browser, which makes the tool suitable for payloads that contain customer or internal data.
Feedback & suggestions
Help us improve JSON Schema Generator. We read every message.