JSON Schema from a sample — Draft 2020-12 / Draft-07
Paste an API response or config-file JSON sample and get a corresponding **JSON Schema (Draft 2020-12 / Draft-07)** automatically. Types are inferred from values (`string` / `number` / `integer` / `boolean` / `array` / `object` / `null`), array element shapes are merged into a single `items`, and required keys are listed. Toggle strict mode (`additionalProperties: false`), nullable mode (`[T, "null"]`), and string-`format` detection (`email`, `uri`, `uuid`, `date`, `date-time`, `time`, `ipv4`, `ipv6`). Great for scaffolding OpenAPI 3.1 / AJV / VS Code settings JSON Schema / `package.json` schema / GitHub Actions workflow schema. Sister tool to `json-to-ts` (which targets TypeScript types) — use this one for API docs / validation, json-to-ts for source-code type definitions. Runs entirely in your browser; nothing is uploaded.
How to use
Paste a JSON sample or pick one (user, API response, array items, nullables). Toggle Draft (2020-12 / 07), strict, nullable, format detection, integer inference. The matching JSON Schema is generated instantly. Copy or download as `.json`. The output can be plugged straight into OpenAPI 3.1 (Draft 2020-12) or AJV (Draft-07 / 2019-09 / 2020-12).
In depth
Schema inference exposes your data model
Generating a JSON Schema requires an input sample. Those samples are often real API responses, database exports, or form submission examples — which means they may contain email addresses, user IDs, permission roles, or transaction figures. The generated schema then makes the data model explicit: additionalProperties: false, format: "email" annotations, and field names together give anyone reading the schema a detailed map of the application’s internals.
A JSON Schema is roughly equivalent in information density to a database schema. Sending it — or the sample it was derived from — to an external service is handing over a structural blueprint of your application.
The risk of submitting sample data to a schema generator
Online JSON Schema generators receive the full input JSON and process it server-side. If the sample contains real user data, it arrives on the server. The generated schema is also a document — its field names and type annotations are a readable description of your data model that the operator can log or analyse.
Development teams often reach for real data when generating schemas precisely because it gives better field coverage. That pragmatic choice becomes a data exposure if the tool used is a server-side service.
JSON.parse and local type inference keep everything in the browser
This tool parses the input with JSON.parse and walks the object tree recursively, inferring each field’s type locally. Format detection (email / uri / uuid / date / date-time / ipv4 / ipv6) uses local regex matching — no external call. The output JSON Schema conforms to the chosen draft ($schema URI is included) and can be downloaded as .json.
Input sample and output schema both live only in page memory. Paste production-sample data, generate the schema, copy the schema out — and nothing is transmitted to a server throughout.
Wiring directly into OpenAPI 3.1 and AJV
The Draft 2020-12 output slots directly into OpenAPI 3.1 components/schemas. The Draft-07 output is immediately usable with ajv.compile(). Add strict: true to generate additionalProperties: false for APIs that should reject unknown fields. Pair this tool with json-to-ts to get both a TypeScript interface and a JSON Schema from the same sample, covering compile-time and runtime validation with a single source. Normalising the input via json-format first reduces noise when iterating on the sample.
What single-sample inference can and cannot determine
Schema inference from a single sample is fundamentally a generalisation problem, and there are limits to how much can be deduced. This tool assigns string / number / integer / boolean / array / object / null from JavaScript literal types, with arrays merged into a type union where elements differ ([1, "x"] becomes { "type": ["integer", "string"] }). The integer vs number split is made by Number.isInteger() — because JSON parsing collapses 1.0 to 1, a sample that happens to contain only integers will produce a schema that rejects future decimals.
format detection works by matching the string value against regexes; this is an annotation, not a strict validator. Full RFC 5322 email validation is intentionally beyond scope — production validation runs through AJV with ajv-formats, which encodes the more elaborate rules. enum is not inferred automatically: values like status: "active" stay as plain string because deducing “this field is an enum” from a single sample is over-reach. Real-world workflows expect users to hand-edit enum, minLength, and pattern after generation.
Draft 2020-12 vs Draft-07 vs OpenAPI 3.0 dialect differences
JSON Schema has evolved through IETF drafts, and the dialects this tool produces are not identical. In Draft-07, items: [A, B] denoted a tuple where position 0 must be A and position 1 must be B. In Draft 2020-12 that meaning moves to prefixItems; items becomes “the type of any element beyond the prefix.” $id / $ref resolution also gained $dynamicRef in 2020-12, which older toolchains do not understand.
OpenAPI 3.0 is anchored to Draft-04/05-era JSON Schema and uses a proprietary nullable: true keyword, plus a boolean form of exclusiveMinimum. OpenAPI 3.1 finally aligns with JSON Schema 2020-12, making the natural type: ["string", "null"] nullable representation legal. Because the nullable mode in this tool follows 2020-12, pasting that output into an OpenAPI 3.0 document requires rewriting it to nullable: true. When targeting AJV, the Draft-07 output runs unmodified on AJV v6 / v7 / v8, while Draft 2020-12 requires ajv/dist/2020 and a more recent AJV release.
FAQ
- How is this different from json-to-ts?
- json-to-ts generates TypeScript `interface`/`type` declarations (source-code types). This tool generates JSON Schema (API validation, OpenAPI, config-file schemas). Sister tools that give different output from the same sample.
- Draft 2020-12 vs Draft-07?
- Draft 2020-12 (2020) is the latest spec — OpenAPI 3.1 uses it. Draft-07 (2017) is what AJV (the most popular JS validator) ships by default. They differ in `$id` handling and how `items` works (Draft 2020-12 introduces `prefixItems`). We emit the right `$schema` for the chosen draft.
- When should I use strict (additionalProperties: false)?
- When API validation should reject unknown fields, or when a config file should error on typos. Leave it off for extensible APIs.
- What does the nullable option do?
- If a value is `null`, the field's `type` becomes a union: `["string", "null"]`. With nullable off we ignore null values and infer the non-null type only. Draft 2020-12 union-type form works in OpenAPI 3.1 and AJV.
- Which strings are detected as a `format`?
- (1) `email`: light RFC 5322 check; (2) `uri`: starts with `http(s)://`; (3) `uuid`: 8-4-4-4-12 hex; (4) `date`: `YYYY-MM-DD`; (5) `date-time`: ISO 8601; (6) `time`: `HH:MM:SS`; (7) `ipv4`: dotted quad; (8) `ipv6`: light check. Regexes are strict to avoid false positives.
- integer vs number?
- On: integers like `42` get `"type": "integer"`; floats like `3.14` get `"type": "number"`. Off: both become `number`. OpenAPI and JSON Schema 7+ both distinguish them.
- Mixed array items (e.g. `[1, "a"]`)?
- `items` becomes a `oneOf` (Draft 2020-12) or a union `type: ["integer", "string"]`. Primitive unions are emitted as the simpler union; mixed-shape objects use `oneOf`.
- Is anything uploaded?
- No. `JSON.parse` + local inference only.
How to verify nothing is uploaded
This tool never sends your input outside your browser. The pages below explain how it works, how to audit it, and how the site is run.
Related tools
JSON to TypeScript Type Generator
Paste JSON to generate matching TypeScript interface / type definitions. Nested objects become separate interfaces, arrays merge their keys (keys present in only some elements become optional with ?), and mixed values turn into union types. Choose the root type name, interface vs type, and whether to add export. Identical shapes are deduplicated into one type. JSON is processed entirely in your browser and never uploaded.
JSON format & validate — indent, minify, error pointer
Format, minify, and validate JSON entirely in your browser. Errors show the line and column. Your data never leaves your device.
JSON diff — structural compare of two documents
Compare two JSON documents structurally. Walks nested objects and arrays recursively and highlights added / removed / modified / moved entries. Runs entirely in your browser.
JSON Path query — query JSON trees with JSONPath
Run JSONPath queries (e.g. `$.store.book[*].author`) against JSON data and pull out exactly what you need. Powered by jsonpath-plus (MIT) inside the browser. Pick what to return — values, paths, or parent nodes. Great for slicing API responses, fishing specific fields out of logs, sanity-checking config files, or exploring JSON in DevTools. Filter expressions like `?(@.price < 10)`, recursive `$..`, and tag matches `[?(@.tag=='x')]` are all supported. Everything is evaluated locally — no upload.