Skip to content
Tools

JSON Schema Generator

Last updated:

Paste a sample JSON document and get a JSON Schema that describes it: the type of every value, nested properties, array item schemas and a required list. It is a starting point you then tighten with formats, enums and limits that a single sample cannot reveal.

Runs in your browser: your sample never leaves your device – nothing is uploaded, logged or stored on a server. How we protect your data

100% in-browserNothing is uploaded

Input

Loading editor…

Paste a JSON sample

or drop a file anywhere in this box. Everything stays in your browser.

Drop a file to load it

Output

Loading editor…

The schema appears here

Results update as you type.

How to use the JSON Schema Generator

  1. Paste one representative JSON document. To cover variations, wrap several records in one array; array items are merged.
  2. Pick draft 2020-12 (default) or draft-07, and toggle string formats, forbid extra properties and merging array items.
  3. Add constraints a sample cannot show: enum, minimum, maxLength, pattern.
  4. Test it in the JSON Schema validator against both good and bad documents.

Worked example

A small user record

Input

{"id":1,"email":"ada@example.com","tags":["admin"]}

JSON Schema

{
  "$schema": "https://json-schema.org/draft/2020-12/schema",
  "type": "object",
  "properties": {
    "id": {
      "type": "integer"
    },
    "email": {
      "type": "string",
      "format": "email"
    },
    "tags": {
      "type": "array",
      "items": {
        "type": "string"
      }
    }
  },
  "required": [
    "id",
    "email",
    "tags"
  ]
}

Every key in the sample is marked required; remove keys that may be absent. "format": "email" was added because the value looks like an email (turn off string formats to omit it).

What a generator can and cannot infer

What a generator can and cannot infer
RuleInferred from a sample?Add by hand
TypesYes
Nested properties and itemsYes
requiredYes, but over-eager: every key seenTrim optional keys
additionalPropertiesOption: "Forbid extra properties" sets falseOr set it per object
enum / constNoList allowed values
format (email, date-time, date, uri, uuid, ipv4)Yes, for strings that clearly match (option, on by default)Remove any false positives
minimum / maxLength / patternNoAdd business limits

Arrays with mixed items

If array items differ, the generator merges them: a key present in only some items is left out of that items schema's required list, and a value seen as both a string and a whole number gets "type": ["string", "integer"] ("number" if any value had a decimal point). For arrays of different kinds of objects, rewrite the result with oneOf and a discriminating property.

Which draft to use

Draft 2020-12 is the current published version and is supported by Ajv, the Python jsonschema package and most modern validators. OpenAPI 3.1 uses 2020-12 as well; OpenAPI 3.0 uses an older, modified subset, so check nullable and exclusiveMinimum if you paste the schema there.

JSON Schema Generator FAQ

What is a JSON Schema used for?

It describes what valid JSON looks like – types, required keys, value limits – so that tools can validate data automatically, generate documentation and forms, and power editor autocomplete.

Can I generate a JSON Schema from an API response?

Yes. Paste the response body. The generator reads one document, so if fields vary between responses, combine them into a single JSON array: merged array items capture optional keys and nullable values.

Why is every property listed as required?

The generator only sees keys that are present in the sample, so it cannot know which are optional. Remove keys from the required array that the API may omit.

How do I disallow extra properties in JSON Schema?

Add "additionalProperties": false next to properties. Validation then fails for any key not declared.

How do I allow null for a property?

Use a type array: "type": ["string", "null"]. In OpenAPI 3.0 use "nullable": true instead.

What draft does the generated schema use?

Draft 2020-12 by default, declared in the $schema keyword at the top. Draft-07 is available in the options for older validators.

Related tools