JSON to JSON Schema Generator
CV-75Paste a JSON sample and press Convert to get a draft 2020-12 schema with types and required keys. It infers the types from every item in your sample, and it runs in your browser.
Runs in your browser. Nothing is uploaded.
JSON
JSON Schema
How to use it
- Paste a JSON sample into the input box, or open a .json file. Use a sample that shows every key you expect.
- Choose the indent, whether keys in every object are required, additionalProperties: false, and format detection.
- Press Convert, then copy the result or download it as a .json file.
- Validate documents with any validator that supports draft 2020-12, and tighten the schema by hand where the sample was too loose.
How the schema is built
The schema declares the draft 2020-12 dialect in $schema and gives every value a type: object, array, string, integer, number, boolean or null. Keys that appear in every object of the sample go into required, and keys missing from some objects stay optional. Integers and decimals stay apart, so 1 is integer and 1.5 is number; mixed types become a type list or an anyOf. Arrays get an items schema merged from every item, and an empty array gets none.
How the JSON is read
If the document is a top-level array, its items are merged into one type named after the root name with Item added. The JSON is read with a parser that keeps number text exactly, so a big integer is not rounded before its type is chosen. Every object in the sample is merged by key, so a key missing from some objects is marked optional and a null in some items marks the key nullable. Keys that are not valid JSON Schema names, such as first-name, are renamed, and the original key is kept in the property name, kept exactly as written.
What a sample cannot tell it
The result only reflects the sample you paste: a key that never appears has no member, and a number that is always whole in the sample is typed as whole even if other data holds decimals. It writes no minimum, maximum, pattern, enum or length limits; add the rules that matter by hand. Check the result against the API documentation before you rely on it.
Questions people ask
How do I convert JSON to a JSON Schema?
Paste the JSON into the input box, choose your options and press Convert to get the schema keywords. Validate documents with any validator that supports draft 2020-12, and tighten the schema by hand where the sample was too loose. The conversion happens in your browser.
Which JSON Schema version does the generator write?
Draft 2020-12, declared in the $schema keyword at the top. If your validator only knows an older draft, check its support for 2020-12 or edit the declaration; keywords such as type, properties, required and items also exist in older drafts.
Why are some keys not listed under required in the generated schema?
Only keys that appear in every object of the sample are required. A key missing from some objects stays optional. Turn the required option off to list none, or edit the list by hand if the sample did not show your real rules.
What does the additionalProperties option do in the schema?
Switched on, every object gets additionalProperties: false, so a document with a key the sample did not show fails validation. Leave it off for the default JSON Schema behavior, which accepts extra keys.
What happens when my JSON starts with an array?
The tool reads every item and merges them into one type, so a key present in only some items becomes optional. The output names that type after the root name with Item added, and a comment at the top says the document is a list. The JSON Schema schema keywords are written from the parsed sample.
How are very large numbers in the JSON sample handled?
Number text is kept exactly while types are picked, so a value like 12345678901 gets a 64-bit type where the language has one, and an integer beyond 64 bits is flagged rather than silently rounded. JSON Schema only records integer or number. The JSON Schema schema keywords are written from the parsed sample.
About this tool
The classes are inferred from the JSON you paste, so they only know what the sample shows. It writes a JSON Schema using the draft 2020-12 dialect: a type for every value, properties for objects, items for arrays, and null, integer and number kept apart. Keys present in every object of the sample go in required (switch that off to list none), and mixed types become a type list or anyOf. The format detection option adds date-time, date, time, email, uuid, uri or ipv4 to strings that match. It cannot know ranges, patterns, enums or lengths, so none are written. Everything runs in your browser; nothing is uploaded.