How to Generate a JSON Schema From Sample JSON

Updated 2026-06-21

To generate a JSON Schema from existing JSON, paste a representative sample into a schema generator and let it infer the structure — the types, properties, and required keys — into a draft-07 schema you can save and reuse. The JSON Schema Generator & Validator does exactly that in your browser, then lets you validate fresh JSON against the result without writing a single rule by hand.

Generate a schema from sample data

Writing a schema by eye is slow and error-prone. It is far easier to start from data you already have:

  1. Copy a real example of your JSON — an API response, a config file, or one record from a dataset.
  2. Paste it into the generator.
  3. Read off the inferred draft-07 schema, which includes a $schema declaration, the top-level type, every property, and a required list.

The tool walks the value recursively. Objects become a properties map, arrays get an items schema describing their elements, and primitives are typed precisely — whole numbers are reported as integer while decimals become number, so you do not over-constrain or under-constrain numeric fields.

How inference handles arrays and optional fields

Two details make the inferred schema accurate rather than naive.

First, arrays are merged across elements. If a list contains objects with slightly different shapes, the generator combines them and, where a field holds more than one kind of value across samples, it emits a type union (for example, a value seen as both string and null). That mirrors how real-world payloads actually vary.

Second, required is computed conservatively. When you feed multiple records, a key is only marked required if it appears in every sample. A field present in some records but missing in others is left optional — which is almost always what you want for an API contract.

The practical takeaway: feed in several representative examples, not just one, so optional fields are correctly recognized instead of being locked in as mandatory.

Validate JSON against your schema

A schema is only useful if you can check data against it. Once you have a schema — generated here or pasted from elsewhere — switch to validation, drop in a JSON document, and the tool checks it with ajv, a standards-compliant draft-07 validator. You get a clear pass or a list of the exact paths that failed, so you can see precisely which field is the wrong type or which required key is missing.

Common uses:

Why in-browser matters

Everything — inference and validation alike — runs entirely in your browser. Your JSON never leaves your machine, so you can safely paste production payloads, customer records, or internal API responses without sending them to a third-party server. There is no signup, no upload, and no rate limit.

Ready to turn a sample payload into a real contract? Open the JSON Schema Generator & Validator and paste your JSON to get a draft-07 schema you can validate against in seconds.

Try the JSON Schema Generator & Validator →