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.
A single object cannot reveal which keys are optional. Paste an array of several samples to detect them.
Technical Guide & Mechanics
Authoring Draft 2020-12 JSON Schemas from Examples
JSON Schema (Draft 2020-12) is the industry standard for API contracts, OpenAPI specifications, and edge validation. Hand-writing schemas with $defs, required arrays, and validation constraints is notoriously tedious.
This tool generates standards-compliant Draft 2020-12 schemas from JSON samples. It inspects strings to automatically infer standard formats—including date-time, email, uuid, uri, and ipv4—where applicable.
Shared object patterns are hoisted into $defs and referenced via $ref, producing modular, readable schemas that integrate directly into Swagger, Ajv, and API gateways.
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.
- Is Draft 2020-12 supported by OpenAPI 3.1?
- Yes, OpenAPI 3.1 natively aligns with JSON Schema Draft 2020-12, including $defs and type arrays.