Generate a JSON Schema (draft 2020-12) from an example JSON document. Types, object properties, required lists and array item schemas are inferred; business rules like formats and ranges are yours to add.
Show calculation steps
Processed privately in your browser — nothing you paste is uploaded, logged or stored.
Honest schema inference
Paste a real payload and get a starting schema in JSON Schema draft 2020-12. The generator infers what the sample actually proves: value types (with whole numbers as integer if you keep that option on), object properties with a required list, and merged item schemas for arrays. What it deliberately does not do is guess — no invented format, minimum or pattern constraints, because a wrong constraint silently rejects valid data later.
Worked example
Input:
{ "id": 101, "name": "Aarav", "score": 8.5, "tags": ["a", "b"], "lastLogin": null }Output (abridged):
{
"$schema": "https://json-schema.org/draft/2020-12/schema",
"type": "object",
"properties": {
"id": { "type": "integer" },
"name": { "type": "string" },
"score": { "type": "number" },
"tags": { "type": "array", "items": { "type": "string" } },
"lastLogin": { "type": "null" }
},
"required": ["id", "name", "score", "tags", "lastLogin"]
}Note lastLogin: one sample can only prove “null here”. If the field is sometimes a date string, widen it to {"type": ["string", "null"]} by hand — or paste an array of several real records, which lets the generator infer unions and optionality from evidence.
When to use it
- Bootstrapping request/response validation for an API that grew without a contract.
- Documenting an integration payload for a partner team.
- Creating the schema side of a test suite from captured production samples.
Limitations to know
- Sample-based inference cannot see business rules. Ranges, formats and patterns must be added by you.
- Empty arrays stay
{"type": "array"}with noitems— the sample holds no evidence of the element type. - From an array of objects,
requiredbecomes the keys present in every element; a field present in just one sample record is optional in the schema.
Common errors and fixes
- Union like
"type": ["integer", "string"]appeared — the same field held different types in different places; that is your data telling you about an inconsistency worth checking upstream. - A whole number became “integer” but the API can send decimals — untick integer detection, or widen that property to
numbermanually. - Schema seems too strict — that is the all-keys-required default; untick it, or generate from an array of varied samples so optionality is inferred.
Test the result immediately: feed it to the JSON Schema Example Generator and check the sample it produces looks like your real data.
How to use the JSON to JSON Schema Converter
- Paste an example JSON document — a real API response works well.
- Choose whether all object keys are marked required, and whether whole numbers become "integer".
- Click "Generate schema" to get a JSON Schema draft 2020-12.
- Add business constraints the sample cannot reveal — formats, minimum/maximum, patterns — then copy the result.
Frequently asked questions
Which JSON Schema version does this generate?
Draft 2020-12 — the current version of the specification — declared explicitly via the $schema keyword at the top of the output.
Why is every property marked required?
A single example cannot reveal which fields are optional, so by default all present keys are required (you can switch this off). The exception: for arrays of objects, keys missing from some elements are inferred optional automatically — required becomes the intersection.
Can it detect formats like email or date?
No, deliberately. Guessing "format": "email" from one sample value would frequently be wrong, and a wrong format constraint rejects valid data. The tool infers only what the sample proves — types, structure, required keys — and leaves formats to you.
What does it do with empty arrays?
It emits { "type": "array" } without an items schema, because the sample contains no evidence of the element type. Inventing one would make the schema lie about your data.