Skip to content
DevTinyTools

JSON to JSON Schema Generator

Paste a JSON sample and get a draft 2020-12 schema as you type. Required keys, integer vs number, nullable unions and nested $defs are inferred from every array element — all in your browser.

Runs entirely in your browser — your JSON is never uploaded.

0 chars
0 types

Inference and schema emission run here in the tab — the JSON you paste never leaves the browser. A sample describes what it saw: keys absent from every record cannot be marked required, and a field can still be absent in the next response.

How to generate a JSON Schema from a sample

  1. Paste one or many examples A single object works, but an array of real responses is better: every element is sampled, so keys that only some records carry become optional instead of wrongly required.
  2. Name the root and pick an indent The schema title is used for the root object and for any nested type names. Two or four spaces controls the pretty-printed output.
  3. Choose how strict to be Reject unknown keys writes additionalProperties: false on every object, so a validator fails on fields the sample never showed. Turn it off for responses that gain fields over time.
  4. Copy or download the .schema.json The output is ready to drop into an editor setting, a CI validation step or a schema registry. Nothing was uploaded to get it.

What the generator decides for you

Turning a sample into a schema is mostly mechanical, but a few decisions decide whether the result accepts tomorrow's data or rejects it. This tool makes those decisions the same way the code generators on this site do: from evidence in the sample, never from a guess.

  • Required means observed. A key is required only if every sampled element carries it. A single record is marked required in full, which is honest about how little evidence it had.
  • Numbers widen safely. A whole number becomes integer, but one fractional value widens the field to number so the schema keeps validating.
  • Mixed primitives become type arrays. A field that is a string in one record and null in another is emitted as { "type": ["string", "null"] }; mixtures involving objects use anyOf.
  • Nested objects get names. Repeated shapes are hoisted into $defs and referenced with $ref, so the root reads top-down instead of as one deeply nested literal.

Where a sample stops being enough

A generated schema is a starting point, not a contract. It cannot know that a field holding 129.5 is a price and not a quantity, or that an ISO date string should carry a format: date-time rule. Add those four constraints by hand before you rely on the schema in CI.

  • Which keys are truly required in every future response.
  • Which numbers are money, and need a decimal or integer-minor-units rule.
  • Which strings are dates, emails, UUIDs or URLs, and need a format.
  • Which fields are enums rather than any string at all.

The same sampling rule matters when the underlying values are large integers: by the time JavaScript reads them, precision may already be gone. The guide to why JSON numbers lose precision explains what to watch for before you generate a schema from such a payload.

Frequently asked questions

What is a JSON Schema, and why would I want one?
A JSON Schema is a document that describes the shape of other JSON documents: which keys exist, which are required, and what type each value is. Editors use it for autocomplete and inline validation, test suites use it to check that an API response did not drift, and form builders use it to render fields. Paste a sample response here and you get a starting schema you can tighten by hand.
Which draft of JSON Schema does this generate?
Draft 2020-12, the current standard. You will see $schema set to the 2020-12 meta-schema URI and nested object shapes collected under $defs and referenced with $ref, which is the 2019-09-and-later spelling (older drafts called the same thing definitions). Any modern validator — Ajv, ajv-formats, Python's jsonschema, Zod's schema imports — reads it.
How does it decide which keys are required?
By sampling, not guessing. Paste a single object and every key is required, because that is all the tool saw. Paste an array and the tool walks every element: a key present in all of them lands in required, a key missing from any of them stays optional. This is why an array of real responses produces a far more useful schema than one hand-picked example.
Why is one field integer and another number?
Whole-number samples become integer; a single fractional value widens the same field to number. If one record has 4 and another has 19.5, the schema says number, because integer would reject the second record. Widening is the safe direction — a schema that is slightly too permissive still validates your data, while one that is too strict fails on the next response.
What happens to a value that is a string in one record and null in another?
It becomes a union type: {"type": ["string", "null"]}. Unions made only of primitive types collapse into that compact type array. A union that involves an object cannot be written that way, so the tool uses anyOf instead — the only honest encoding of 'this is either an object or something else'.
What does 'Reject unknown keys' change?
It toggles additionalProperties on every object. On (the default) writes additionalProperties: false, so a validator rejects any key the schema did not see in the sample — useful when you want drift to fail loudly. Off omits the keyword, so extra keys are accepted, which suits responses that gain fields over time. Neither changes the schema's required list.
Does a generated schema describe my whole API?
No. It describes exactly the sample you pasted: a field absent from every record cannot be marked required, a money value is still just a number, and a date string carries no format rule. Treat the output as a correct skeleton, then add the four decisions a sample cannot make — which keys are required, which numbers are money, which strings are dates or emails, and which values are enums.
Is my JSON uploaded anywhere?
No. Parsing, type inference and schema emission all run in this browser tab. There is no upload endpoint and nothing is stored, so a payload containing customer records or internal hostnames never leaves the machine. The page keeps working offline once it has loaded.
JSON RepairFix broken JSON from an assistant or a config file: fences, comments, single quotes, trailing commas, Python literals and truncated tails — with every change reported.JSON Formatter & ValidatorPretty-print JSON with 2 or 4 space indentation, check the syntax and copy or download the result.JSON ValidatorCheck whether a JSON document is valid and see exactly where the parser stopped.JSON MinifierStrip whitespace from JSON and see how many bytes the minified output saves.JSON Diff CheckerCompare two documents and list every added, removed and changed value with its path.JSON Escape & UnescapeTurn raw text into a JSON string value, or decode backslashes and \u escapes back into readable text.JSON to CSV ConverterTurn an array of JSON objects into a CSV file you can open in a spreadsheet.JSON to TypeScript GeneratorGenerate TypeScript interfaces from a JSON sample, with optional properties and unions inferred from every array element.JSON to Go Struct GeneratorGenerate Go structs from a JSON sample, with json tags, int64 or float64 widths, pointers for null fields and omitempty for optional keys.CSV to JSON ConverterConvert CSV to JSON with RFC 4180 parsing, delimiter detection, dotted headers unflattened into nested objects and numbers converted only when they round-trip exactly.JSON to Java POJO GeneratorGenerate Java classes from JSON: primitives for required values, boxed types for optional and nullable ones, @JsonProperty for renamed keys and nested static classes.JSON to YAML Converter (and back)Convert JSON to YAML or YAML to JSON in both directions, with multi-document support, error line numbers and YAML 1.2 typing rules.JSON to Python Class GeneratorGenerate Pydantic v2 models or dataclasses from JSON, with snake_case fields, Optional where a key is missing or null, and keyword keys renamed safely.JSON to C# Class GeneratorGenerate C# classes from JSON with nullable annotations taken from every record, initialisers that avoid CS8618 and [JsonPropertyName] for each wire key.