Generate a JSON Schema from JSON

Paste a JSON example or a list of samples and get a draft 2020-12 schema with types, required keys and formats. Nothing is uploaded.

How it works

  1. Paste one JSON value or a list of samples
  2. Choose the required, format and extra-key options
  3. Copy the schema

How the schema is inferred

To generate a JSON Schema from JSON, paste an example or a list of examples and the tool writes a draft 2020-12 schema with the types, nested objects, array items and required keys it finds. Strings, booleans and null get their own type. A number is an integer when every number at that place is a whole number, and number as soon as one has a decimal part, so 1 and 2.5 together give number. Objects list every key seen in properties. Arrays get one items schema built from all the items of all the arrays at that place. An empty array gives an array with no items, because there is nothing to learn from it. A value such as 1.0 is read by the browser as 1, so it counts as an integer, which JSON Schema 2020-12 also allows.

Required keys and several samples

A key is required when it is present in every object seen at that place. Worked example: the samples {"id":1,"name":"Ada"} and {"id":2,"score":4.5} give properties id as integer, name as string and score as number, and required lists only id. A key whose value is null still counts as present. With Treat a top-level array as separate samples on, which is the default, each item of a top-level array is one sample and the schema describes one item. Turn it off to describe the array itself. Mark every key as required lists all keys instead, and Forbid extra keys adds additionalProperties: false to every object, so the schema rejects keys it has not seen.

Null, mixed types and formats

When null appears at a place, the type becomes a list such as string and null. Two or more primitive types also become a list: a string in one sample and a number in another give string and integer. When an object or an array is mixed with another type, the schema uses anyOf with one entry per type, because their keywords cannot share one list. Detect string formats adds a format only when every string at that place matches the same one: date-time such as 2025-03-01T10:00:00Z, date such as 2025-03-01, email, uri with a scheme such as https:// or mailto:, or uuid. Dates must be real, so 2025-02-30 gets no format. Strings longer than 2,048 characters are never given a format. Email is judged conservatively: ASCII only, no leading, trailing or doubled dot before the @, and a domain with at least one dot, so a..b@example.com and a@localhost get no format. Format is an annotation unless a validator is told to assert it.

What a schema from examples cannot know

The schema describes the examples you gave and nothing more. It cannot know that a field is an enum, that a number has a minimum, that a string has a maximum length, or that a key missing from your samples is allowed, so review it before you rely on it. Add those keywords by hand, along with a title and a description if you want them: the page does not add either, so nothing you type is stored. Numbers larger than 9,007,199,254,740,991 lose digits when read, and when a key is repeated in one object only the last value is read. Up to 1,000,000 characters are handled, nesting deeper than 500 levels is refused, and everything runs in this tab.

Frequently asked questions

How do I generate a JSON Schema from a JSON file?

Paste the JSON into the box. The schema appears at once and the Copy button copies it. If the file is a list of records, leave Treat a top-level array as separate samples on so the schema describes one record and merges the keys of all of them.

Why are only some keys listed as required?

A key is required only when every object in your samples has it. With the two samples {"id":1,"name":"Ada"} and {"id":2,"score":4.5}, required is just id. Turn on Mark every key as required to list all three keys.

How does it handle null values?

A null at a place adds null to that place's type, so a field that is a string in one sample and null in another becomes type string and null. The key still counts as present, so it can be required. If every value is null the type is just null.

Can I add a title or a description to the schema?

Add them yourself after copying: put "title" and "description" next to $schema at the top of the output. The page has no boxes for them, so no text you type is kept. The output is draft 2020-12 and starts with a $schema line for https://json-schema.org/draft/2020-12/schema.

Why is my number typed as integer, not number?

Every number at that place is a whole number in your samples, so integer is the tightest type that fits. If a field can hold 4.5 as well, include a sample with a decimal and it becomes number. A value written 3.0 is read as the whole number 3.

Is my JSON uploaded?

No. The JSON is processed in your browser and not uploaded. Only the option values, such as the toggles, are saved in this browser, never the JSON.