Inferring a schema from sample JSON
Automatic schema generation walks a JSON value and emits a JSON Schema that describes shapes seen in the sample: object keys, array items, and primitive types. It does not read your API documentation or business rules—it only generalizes structure.
Output is a starting draft. You still add enums, patterns, min/max, descriptions, and tighten required lists before treating the schema as a contract. Cross-check payloads on the JSON Schema validator page.
JSON Schema — background
What inference can and cannot do
Inference observes values: a string becomes type string, an integer without fraction becomes integer, 3.14 becomes number, true/false become boolean, null becomes null. It cannot know that a field is optional unless your sample set shows it missing—one object makes every seen key look required.
Arrays of objects and required
When the root (or a nested value) is an array of objects, the generator compares keys across elements. A key present in every item stays in required; a key missing from some items is omitted from required. That is the main way to infer optionality from data alone.
Nested objects and items
Each object level gets its own properties and required. Arrays get an items schema—either a single schema for homogeneous arrays or a merged shape from observed elements. Deep nesting in the sample produces deep nesting in the schema; ordering follows the sample, not alphabetical sort.
Infer format and $schema
Optional Infer format heuristically adds format (email, uri, uuid, date, date-time) when a string looks like one. It is pattern matching, not validation of real-world correctness. The chosen draft (2020-12, 2019-09, draft-07) sets the $schema URL at the top of the generated document for downstream validators.
Where inference fits
Bootstrap, then refine
Use one or more real responses to sketch properties and types, then hand-edit: drop spurious required, add enum for status codes, set additionalProperties: false if your API rejects unknown fields.
Not a substitute for design
Schemas encode policy (allowed ranges, mutual exclusions, conditional branches with if/then). Inference never sees policy—only snapshots. Treat generated JSON Schema as material to review, not as authoritative spec.