What this tool does
A JSON sample becomes a JSON Schema in draft 2020-12.
{ "id": 1, "name": "Ada", "address": { "city": "Paris" } }
{
"$schema": "https://json-schema.org/draft/2020-12/schema",
"type": "object",
"properties": {
"id": { "type": "integer" },
"name": { "type": "string" },
"address": {
"type": "object",
"properties": { "city": { "type": "string" } },
"required": ["city"]
}
},
"required": ["id", "name", "address"]
}
Nested objects are written in place. There is no $defs section and no $ref: for a sample, an inlined schema is the one you can read top to bottom.
Two switches, because both answers are defensible
- Required keys. On by default: every key of the sample is listed. Off: no
requiredarray at all, so a document missing a key still validates. additionalProperties. Permissive by default — an extra key passes. Set it to strict and"additionalProperties": falseis added to every object, so an unexpected key is an error.
Neither choice can be read off a sample. They are statements about your API, so they are yours to make rather than ours to guess.
integer and number come from the literal
3 gives integer; 3.0 and 1e3 give number. JSON has a single numeric type, so the way a number was written is the only trace of what produced it. A schema calling 10.0 an integer rejects 10.5, most likely the next record — this tool did exactly that until the defect was found and fixed while writing these pages.
What the sample does not describe
"n": nullgives{"type": "null"}, a schema accepting nothing else. If the field is a nullable string,{"type": ["string", "null"]}is the edit.- An empty array gives
{"type": "array"}with noitems: nothing is claimed about elements that were never seen. - A mixed array gives
anyOf, listing exactly the shapes present. - No
format, nominLength, nopattern. An email, a UUID and a sentence are all"type": "string"here. Adding"format": "email"would be a guess about meaning, not a reading of structure — and it is the first thing worth adding by hand once you know the field.
Private by design
Everything runs locally in your browser with JavaScript. Your data is never uploaded, which makes the tool safe for sensitive content, and it keeps working offline.