JSON to JSON Schema
Infers a JSON Schema from one or several samples, unioning the shapes it sees.
Describes a sample document as a JSON Schema (2020-12): types, properties, `required`, and nested `$defs` for repeated shapes. Useful for a contract test, an OpenAPI component, or anywhere a validator wants a schema rather than an example.
Sample JSON
Drop a .json file
Read in this tab. Nothing is uploaded.
Give it every element you have. Every extra record narrows the guess — a field missing from one of them is what makes it optional.
TypeScript
How to use it
Paste as many records as you have
Every element of every array is read and merged, not just the first. Three records tell it far more than one, because a field missing from one of them is exactly what makes that field optional.
Name the root type
Nested objects are named after the key that holds them, singularised for arrays, so `users` yields a `User`. Only the root needs a name from you.
Read the counts under the output
Types, optional fields, unions and how many records were merged. A union count above zero means a field held two different kinds of value across your sample — worth looking at before you paste the result into a codebase.
Take the schema to a validator
The output carries its `$schema` keyword, so it can go straight into the JSON Schema validator on this site or into any 2020-12 implementation.
Common questions
Which draft is this?
Draft 2020-12, declared in the `$schema` keyword. Reusable shapes go in `$defs` and are referenced with `$ref`, which is that draft’s spelling; Draft-07 tooling wants `definitions` instead and will not resolve these references.
Why is nothing constrained beyond its type?
No `format`, `minLength`, `pattern` or `enum` is emitted. Every one of those would be inferred from a handful of records, and a schema that rejects valid production data is worse than one that is merely loose. Add the constraints you can actually justify.
Is `additionalProperties` set?
It is left open, which means extra keys validate. Closing it would turn every field the API adds later into a validation failure, and a sample cannot tell you whether the shape is meant to be closed.
How does it decide what goes in `required`?
A property is required when it was present in every record that was merged into that shape. Paste one record and everything is required; paste five and the schema starts telling you something real.
Feed it from
JSON to TypeScript
Infers TypeScript interfaces or types from a JSON sample, merging optional and union fields.
JSON to Zod Schema
Builds a Zod schema from a JSON sample, with nullable, optional and enum inference.
JSON Schema Validator
Validates a document against a JSON Schema and reports each failure with its instance path.
JSON Formatter & Validator
Pretty-prints, minifies and validates JSON, pointing at the exact line and column of a syntax error.
Next
These accept what this tool produces, so the result can go straight in.
JSON Schema Validator
Validates a document against a JSON Schema and reports each failure with its instance path.
JSON to TypeScript
Infers TypeScript interfaces or types from a JSON sample, merging optional and union fields.
JSON to Zod Schema
Builds a Zod schema from a JSON sample, with nullable, optional and enum inference.
OpenAPI Linter
Checks an OpenAPI document for missing responses, unused schemas, references that point at nothing and the other faults that break code generators.
JSON ⇄ CSV
Flattens nested JSON into columns or rebuilds objects from a table, with a dot-path column naming rule.
JSON Diff
Compares two JSON documents structurally, ignoring key order and reporting added, removed and changed paths.