JSON Schema Generator

Left: JSON sample—Generate in the left footer. Right: schema output; draft, indent, and Infer format are in the schema header.

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.

Frequently asked questions

What does “JSON to JSON Schema” mean?
It means building a schema document whose types and property tree match a sample instance. The result is JSON Schema syntax (type, properties, required, items), not a different data format.
How do I generate JSON Schema from JSON online?
Paste sample JSON, choose draft and indent in the schema header if needed, and click Generate. Copy the right-hand schema and edit before use.
Why are all fields required in the output?
A single object sample proves each listed key existed at least once, so inference marks them required. Provide an array of varied objects so keys that sometimes absent stay optional.
integer vs number in generated schemas
Whole numbers without a decimal point are usually written as integer; values with fractions become number. If your API always sends 1.0 as a float, the sample may produce number instead of integer—adjust manually.
Should I enable Infer format?
Enable when you want email/uri/date-like strings to carry format in the schema. Disable when strings are opaque codes and format would be misleading.
Which draft should I generate?
2020-12 is the default and aligns with OpenAPI 3.1. Pick 2019-09 or draft-07 when consumers or libraries still expect those $schema URLs.
How is generation different from validation?
Generation creates a schema from data. Validation on the JSON Schema validator tests data against an existing schema. Typical workflow: generate, edit, validate real payloads.