fmt --to=schema --indent=2type a query, e.g. $.users[0].name
IDLE
stdin
1
stdout
Generate a JSON Schema from a sample document, as a starting point you then tighten by hand. It targets draft 2020-12 and is built in your browser.
What the schema describes
The generator walks your sample and records the type of every value: object, array, string, integer, number, boolean or null. Objects get properties, and a key goes into required when it appears in every copy of that object. Arrays get an items schema built from all of their elements.
When a value has more than one type across the sample, plain types become a list such as ["string", "null"], and any mix that includes an object or an array becomes anyOf. Integers and decimals are told apart, so 3 is an integer and 3.5 a number.
What to add yourself
A schema made from one sample can only describe what it has seen. It does not guess formats, enums, minimum or maximum values, patterns or lengths. Add those where your data has rules, and check that every required key really is required.
The schema appears as a tree you can fold, copy or save as a .schema.json file. To test it, open the validator and put the schema in tab b, or press “generate a schema from tab a” there.
Questions
Which draft does it use?
Draft 2020-12, declared in $schema. The keywords it writes mean the same in draft-07, so older tools can read it too.
Why is a key missing from required?
At least one object in your sample does not have it. If the key must always be present, add it to required by hand.
Will the schema reject unexpected keys?
No. It does not add additionalProperties: false, so extra keys pass until you add that rule.