JSON Schema Generator

Generate a JSON Schema (draft 2020-12) from a sample JSON document, locally in your browser.

Generate JSON Schema from JSON

Paste a JSON sample and press Generate. The JSON Schema generator parses the sample, infers a type for every value at every depth, and writes a schema that describes it: nested objects get their own properties and required lists, arrays get an items schema, whole numbers become integer, and values that are sometimes null get a type pair such as ["integer", "null"].

The output is a solid first draft of a contract for an API response, a webhook body or a config file. It records the shape of your data; you then add the business rules a sample cannot show.

How to use the generator

  1. Paste a JSON object or array into Input. Use real data: a richer sample produces a more accurate schema.
  2. Click Generate. The schema appears in the output box, pretty-printed with two-space indentation.
  3. Click Copy, save it as schema.json, and refine it as described below.
  4. Test real payloads against it in the JSON Schema validator.

What it infers

In the sampleIn the schema
"Ada"{"type": "string"}
37{"type": "integer"}
19.5, or whole and decimal numbers mixed across records{"type": "number"}
true{"type": "boolean"}
an object"type": "object" with nested properties and required
an array"type": "array" with one items schema merged from every element
a value that is null in some recordsa type pair such as ["integer", "null"]
a value that is only ever null, an empty array's items, or mixed types{}, which accepts anything

Worked examples

1. A single object

{"id":7,"name":"Ada","price":19.5,"active":true,"address":{"city":"London","zip":"N1"},"tags":["admin","editor"]}

Generated schema:

{
  "$schema": "https://json-schema.org/draft/2020-12/schema",
  "title": "Root",
  "type": "object",
  "properties": {
    "id": {
      "type": "integer"
    },
    "name": {
      "type": "string"
    },
    "price": {
      "type": "number"
    },
    "active": {
      "type": "boolean"
    },
    "address": {
      "type": "object",
      "properties": {
        "city": {
          "type": "string"
        },
        "zip": {
          "type": "string"
        }
      },
      "required": [
        "city",
        "zip"
      ]
    },
    "tags": {
      "type": "array",
      "items": {
        "type": "string"
      }
    }
  },
  "required": [
    "id",
    "name",
    "price",
    "active",
    "address",
    "tags"
  ]
}

Every key is required because the generator saw it once and has no evidence it can be missing.

2. Records with optional and nullable fields

{"users":[{"name":"Ada","age":36,"nick":"ada"},{"name":"Bo","age":null,"score":1.5}]}

Generated schema:

{
  "$schema": "https://json-schema.org/draft/2020-12/schema",
  "title": "Root",
  "type": "object",
  "properties": {
    "users": {
      "type": "array",
      "items": {
        "type": "object",
        "properties": {
          "name": {
            "type": "string"
          },
          "age": {
            "type": [
              "integer",
              "null"
            ]
          },
          "nick": {
            "type": "string"
          },
          "score": {
            "type": "number"
          }
        },
        "required": [
          "name",
          "age"
        ]
      }
    }
  },
  "required": [
    "users"
  ]
}

Merging the two records shows that nick and score are optional (absent from one record each), so they are not in required, and that age may be null.

3. Mixed types in an array

The input [1, "two", 3] has no single item type, so the items schema is left open:

{
  "$schema": "https://json-schema.org/draft/2020-12/schema",
  "title": "Root",
  "type": "array",
  "items": {}
}

Refining the generated schema

When to use a JSON Schema generator

Generate a schema when you need one contract that several languages and tools can share: Ajv in Node.js, jsonschema in Python, OpenAPI component definitions, or editor autocompletion for a config file. If you only need types in one language, generate them directly with JSON to TypeScript, JSON to Pydantic or JSON to Go. To start from XML or YAML instead of JSON, choose that input format on the class generator hub, which can also emit JSON Schema.

FAQ

Which JSON Schema version does it output?

Draft 2020-12. The document starts with "$schema": "https://json-schema.org/draft/2020-12/schema" and a "title" of Root. The keywords it uses also mean the same in draft-07, so you can change the $schema URL if your validator only supports the older draft.

How does it decide which fields are required?

A key is required when it appears in every object the generator saw at that position. With a single sample object every key is required; with an array of records, keys missing from any record are left out of required.

Does it detect formats like email or date-time?

No. Strings are typed as string only. Add format, pattern, enum, minLength and numeric bounds yourself once you know the rules.

How do I generate one schema from several samples?

Put the samples in a JSON array and generate from that. The item schemas are merged, so optional keys and nullable values show up, and you can copy the items schema as your object schema.

Will the schema accept my original JSON?

Yes. It describes the sample, so the sample always validates. Until you add constraints it will also accept many payloads you would want to reject.

Is my JSON uploaded?

No. Parsing and schema generation run in your browser with JavaScript, and the sample never leaves the page.