Generate JSON Schema from a sample
Paste any JSON object and get a valid JSON Schema with inferred types, required fields, and nesting — ready for AJV, form generators, or API docs.
{
"$schema": "https://json-schema.org/draft/2020-12/schema",
"type": "object",
"properties": {
"id": {
"type": "integer"
},
"name": {
"type": "string"
},
"active": {
"type": "boolean"
},
"tags": {
"type": "array",
"items": {
"type": "string"
}
},
"address": {
"type": "object",
"properties": {
"city": {
"type": "string"
},
"country": {
"type": "string"
}
},
"required": [
"city",
"country"
]
}
},
"required": [
"id",
"name",
"active",
"tags",
"address"
]
}How to generate a JSON Schema from a JSON sample
JSON Schema is the lingua franca of JSON validation, form generation, and API documentation. This generator infers a schema from a representative sample so you don't hand-author every nested shape.
- 01
Paste a representative JSON sample
Use a real-world example — API response, config object, or analytics event. The generator infers types and required fields from the sample.
Both pretty-printed and minified JSON work.
Inputs parse through the native
JSON.parsereviver chain — strict RFC 8259. Any syntax error returns line and column for the exact offending byte.sampleAPI responseRFC 8259JSON.parsestrictinput · json · raw.json · RFC 8259{"id":1,"name":"Ada"}loaded · parsed RFC 8259RFC 8259 · ready - 02
Choose Draft 2020-12 or draft-07
2020-12 is the current spec (most modern features, used by latest AJV and most tooling).
draft-07 is the most widely supported — pick this for older Pydantic, AJV 6, or legacy form generators.
2020-12draft-07$schemadraft$schema{ "$schema": "https://json-schema.org/draft/2020-12/schema", "type": "object" }spec-correctready - 03
Review the inferred schema
The generator emits
typeannotations (string, number, integer, boolean, null, array, object),propertiesfor nested fields, andrequiredlists all keys present in the sample.Mixed-type arrays merge into union types. Integer detection:
1→integer,1.5→number.typepropertiesrequiredoutput · schema.json{ "type": "object", "properties": { "id": {"type": "integer"}, "name": {"type": "string"} }, "required": ["id", "name"] }validatedspec-correct - 04
Use with AJV, forms, or docs
Pipe the schema to AJV for runtime validation, react-jsonschema-form to auto-generate UIs, or OpenAPI / Swagger to document your endpoints.
AJVrjsfOpenAPIusageAJVconst Ajv = require("ajv"); const ajv = new Ajv(); const validate = ajv.compile(schema); if (!validate(data)) console.log(validate.errors);spec-drivenvalidated
Production-grade JSON Schema generation
Add constraints by hand
The generator emits types but not constraints — add minLength, format: "email", pattern, etc. for real validation.
Adjust required carefully
All fields in the sample become required. Trim manually if some are optional in production.
Mixed-type arrays
The generator merges types. Verify the resulting union matches your actual data contract.
Use $defs for reuse
For repeated shapes (Address, User), extract to $defs and reference with $ref.
Add format hints
Strings can use format: "email", "uri", "date-time", "uuid" for richer validation.
OpenAPI subset
OpenAPI 3.1 aligns with JSON Schema 2020-12. Earlier OpenAPI versions need slight tweaks.
When to reach for JSON Schema
Wherever you need machine-readable contracts for JSON data.
Runtime validation with AJV
Industry-standard validator. Plug the schema in and reject bad input at the edge. Output round-trips losslessly through JSON.parse + JSON.stringify, so the file you save is byte-identical to what you see. Streaming parsers, jq pipelines, and Postgres jsonb columns all accept the result without complaint.
10× faster to scanAuto-generated forms
react-jsonschema-form, JSON Forms, and Uniforms all render forms from a schema. Skip hand-built UIs. Pairs perfectly with sort-keys + diff for review-friendly fixtures in CI. Whitespace-only churn disappears and reviewers see real changes, which keeps PR comments focused on logic rather than indentation.
form codegenOpenAPI / Swagger docs
OpenAPI 3.1 components.schemas accept JSON Schema directly. One artifact for docs and runtime validation. Handles emoji and non-ASCII via UTF-8 throughout — your data survives copy-paste between editors, terminals, and IDEs. Combining marks and ZWJ sequences come out the other side intact.
OpenAPI readyContract tests
Validate that mock data and real responses both conform to the same schema. Catches drift early. Re-parses on every keystroke so syntax errors are caught at the exact character. Strict RFC 8259 — no trailing commas, no comments, no unquoted keys — keeps downstream parsers happy.
round-trip safeLLM tool definitions
OpenAI / Anthropic tool calls accept JSON Schema. Generate from a sample for instant tool definitions. Streams large documents without a server round-trip — privacy stays in the tab. Heavy parsing runs through useMemo so even 5 MB payloads keep the editor responsive.
tool-call nativeDatabase column constraints
Postgres jsonb columns support JSON Schema validation. Constrain shape at the storage layer. Output is byte-stable: same input plus same options always produces identical bytes, ideal for content-addressed caches and snapshot tests. Downloads ship with the application/json MIME so editors apply syntax highlighting.
DB-level safetyFrequently asked questions
About JSON Schema generation.
Something missing?
Tell us what you need. We ship the top requests every two weeks.