JSON to JSON Schema
JSON Schema is what validates your payloads at the edge, documents your API and generates your client types, which makes writing it by hand from an example both common and tedious. This produces a draft 2020-12 schema with nested shapes hoisted into $defs, the required list derived from which keys every sample had, and format keywords where the values justify them.
target
A single object cannot reveal which keys are optional. Paste an array of several samples to detect them.
how to use it
- 01Paste a JSON object, an array of samples, or NDJSON.
- 02Name the root schema.
- 03Copy the schema into your validator or API description.
questions
- Which keys end up in required?
- Every key that appeared in all samples. A key missing from any one of them is left out, which is why several samples give a better result than one.
- How is a nullable value expressed?
- As a type array, such as [\"string\", \"null\"], rather than a separate nullable keyword, which is not part of JSON Schema.
- Where do format keywords come from?
- From values that every sample matched: date-time, date, email, uuid, uri and ipv4 are detected conservatively.