N
NJHTools

JSON to JSON Schema

Paste a JSON sample and get a JSON Schema describing its types, required properties and nested objects, ready for validation or documentation. Free, no signup, and generated in your browser.

Language

16 lines · processed in your browser, nothing is uploaded

JSON Schema output · root.schema.json

Generated code appears here.

Example: JSON to JSON Schema

This JSON sample, with the root type named User, produces the JSON Schema below using the default options.

Input JSON
{
  "id": 1024,
  "name": "Ada Lovelace",
  "email": "ada@example.com",
  "active": true,
  "score": 98.5,
  "tags": [
    "admin",
    "beta"
  ],
  "address": {
    "city": "London",
    "postcode": "NW1 6XE"
  }
}
Generated JSON Schema
{
    "$schema": "http://json-schema.org/draft-06/schema#",
    "$ref": "#/definitions/User",
    "definitions": {
        "User": {
            "type": "object",
            "additionalProperties": false,
            "properties": {
                "id": {
                    "type": "integer"
                },
                "name": {
                    "type": "string"
                },
                "email": {
                    "type": "string"
                },
                "active": {
                    "type": "boolean"
                },
                "score": {
                    "type": "number"
                },
                "tags": {
                    "type": "array",
                    "items": {
                        "type": "string"
                    }
                },
                "address": {
                    "$ref": "#/definitions/Address"
                }
            },
            "required": [
                "active",
                "address",
                "email",
                "id",
                "name",
                "score",
                "tags"
            ],
            "title": "User"
        },
        "Address": {
            "type": "object",
            "additionalProperties": false,
            "properties": {
                "city": {
                    "type": "string"
                },
                "postcode": {
                    "type": "string"
                }
            },
            "required": [
                "city",
                "postcode"
            ],
            "title": "Address"
        }
    }
}

How to convert JSON to JSON Schema

  1. 1Paste a JSON object or array of records into the input.
  2. 2Select JSON Schema as the output.
  3. 3Name the root type, for example Event.
  4. 4Copy the schema into a .schema.json file.
  5. 5Add constraints such as formats, enums or patterns by hand.

Which draft version?

JSON Schema has several drafts, including draft-04, draft-06, draft-07, 2019-09 and 2020-12. The $schema keyword at the top of the output tells validators which one to use, so keep it.

Most validators, such as Ajv, support several drafts, but some keywords changed between versions; for example, definitions became $defs in 2019-09. Check that your validator supports the draft declared in the output.

Required properties and additionalProperties

Properties present in every record of your sample are listed in required; those missing from some records are left out. Paste several records to get an accurate required list.

Decide whether unknown keys are allowed. Setting additionalProperties to false makes the schema strict, which catches typos but rejects new fields the API may add.

What a schema adds beyond types

A sample cannot show rules such as "must be an email" or "one of these three values". Add format, enum, minimum, maxLength or pattern after generating.

The finished schema can validate data in many languages, document an API, or feed other generators.

Frequently Asked Questions

How do I generate a JSON Schema from JSON?↓

Paste the JSON, choose JSON Schema and copy the result. Types, nested definitions and required properties are inferred from your sample.

Which JSON Schema draft does the output use?↓

Look at the $schema keyword at the top of the generated schema; it names the draft. Make sure your validator supports that draft.

How are required fields decided?↓

A property is required if it appears in every object of the sample. Paste several records so optional properties are detected, or edit the required array afterwards.

Does it handle nested arrays?↓

Yes. Arrays get an items schema, nested objects become reusable definitions, and arrays of arrays are described level by level.

Is my JSON uploaded to a server?↓

No. The code generator (quicktype) runs entirely in your browser, so the JSON you paste never leaves your device. That makes it safe to use with internal API responses, though you should still strip secrets before sharing generated code.

Last updated: