NV ToolkitFormat · Validate · Convert

Code Generators

JSON to JSON Schema Converter

Paste a JSON or XML sample — the format is auto-detected — and get typed JSON Schema models with names, nesting and nullability inferred for you.

In short

Generate a JSON Schema (draft-06) from a sample JSON document: types, required fields and nested definitions inferred — quicktype-powered, in your browser.

By NaveenKumar T · Updated

Learn: JSON Schema Tutorial: Contracts for Your JSON

  • JSON or XML input, auto-detected
  • Nested objects become types
  • Nullability inferred

Runs entirely in your browser — nothing you paste or open here is uploaded, logged, or stored.How we handle data →

Example

Example: JSON order payload to JSON Schema

A small order document with a nested object, an array of two items, a decimal total and a null field — enough to show how each JSON Schema type, list and nullable is inferred. The same page accepts the XML form of this order too, so the sample below is an example rather than the only accepted format. The right-hand side is the exact output of this tool.

Input · JSON
{
  "id": "ord_9F2KX",
  "status": "processing",
  "paid": true,
  "customer": { "name": "Ada Lovelace", "email": "ada@example.com", "phone": null },
  "items": [
    { "sku": "KB-75", "qty": 1, "price": 149.99 },
    { "sku": "MS-12", "qty": 2, "price": 39.5 }
  ],
  "total": 228.99
}
Generated · JSON Schema
{
    "$schema": "http://json-schema.org/draft-06/schema#",
    "$ref": "#/definitions/Root",
    "definitions": {
        "Root": {
            "type": "object",
            "additionalProperties": false,
            "properties": {
                "id": {
                    "type": "string"
                },
                "status": {
                    "type": "string"
                },
                "paid": {
                    "type": "boolean"
                },
                "customer": {
                    "$ref": "#/definitions/Customer"
                },
                "items": {
                    "type": "array",
                    "items": {
                        "$ref": "#/definitions/Item"
                    }
                },
                "total": {
                    "type": "number"
                }
            },
            "required": [
                "customer",
                "id",
                "items",
                "paid",
                "status",
                "total"
            ],
            "title": "Root"
        },
        "Customer": {
            "type": "object",
            "additionalProperties": false,
            "properties": {
                "name": {
                    "type": "string"
                },
                "email": {
                    "type": "string"
                },
                "phone": {
                    "type": "null"
                }
            },
            "required": [
                "email",
                "name",
                "phone"
            ],
            "title": "Customer"
        },
        "Item": {
            "type": "object",
            "additionalProperties": false,
            "properties": {
                "sku": {
                    "type": "string"
                },
                "qty": {
                    "type": "integer"
                },
                "price": {
                    "type": "number"
                }
            },
            "required": [
                "price",
                "qty",
                "sku"
            ],
            "title": "Item"
        }
    }
}

Look for the "phone" field: sampled as null, it is typed as "type": "null". "items" became "type": "array" of Item, and "total" is "type": "number".

Learn more

From JSON sample to JSON Schema types

Hand-writing model classes from a JSON payload is transcription work: read a field, type a property, repeat eighty times, miss one. This page runs quicktype (the same engine behind the best-known generators) against your document, merging array elements to find the common shape and naming nested types from their keys.

The document declares draft-06, and Ajv 8 does not load draft-06 by default — call ajv.addMetaSchema against the draft-06 meta-schema first, or validation fails on the $schema keyword before it ever looks at your data. Python's jsonschema and Java's everit accept draft-06 directly, so this trap is specific to the Ajv/JavaScript toolchain.

How JSON values become JSON Schema types

Inference works from the values in your sample. Strings map to "type": "string", integers and decimals are told apart (228.99 becomes "type": "number", while 1 and 2 stay integral), true/false become the language's boolean, and an object such as "customer" becomes its own named type. The "items" array is typed as "type": "array" of Item because every element shares the same keys — quicktype unifies the shapes of all array elements into one Item type.

Nulls are the one place inference needs your help: "phone": null carries no type information, so the field is emitted as "type": "null". If the real API sometimes sends a string there, include a sample where the field is populated (paste several documents merged into one array) and the generated type becomes the union of what it saw.

Pasting XML instead: how elements and attributes become JSON Schema types

The XML is parsed into a data model before inference (attributes included, text nodes named "text"), so the root element becomes a nested type: <order> is a field of type Order on the top-level Root rather than the top level itself. Child elements become fields, and repeated elements — the two <item> siblings — are collected into "type": "array" of Item under an Items wrapper type that mirrors the <items> container.

Attributes and element text are typed differently, and this matters: element text is type-inferred, so <total>228.99</total> becomes "type": "number", while attribute values are kept as they were written — qty="1" and price="149.99" stay "type": "string" in JSON Schema. Prefer element text for numeric data you want typed, or cast attribute values after decoding. One more trap: a single <item> would not be recognized as a list, so make sure repeated elements appear at least twice in the sample.

Annotations, nulls and nested arrays in the generated JSON Schema

The document declares draft-06 in $schema and its top level is nothing but a $ref pointing at #/definitions/Root — every type, the root included, lives under definitions with a title matching its name. Each object sets additionalProperties to false, so unknown keys fail validation, and lists every property the sample exhibited in an alphabetically sorted required array. Those two defaults are deliberately strict: loosen them by deleting names from required or flipping additionalProperties to true before validating payloads that legitimately carry extra fields.

A property sampled only as null validates as type null and is still listed in required — the schema insists the key be present and empty. Merge a document where the field carries a value and it widens into an anyOf of the observed types plus a null branch, which is the shape you actually want for a nullable field. A property missing from one of the merged samples simply drops out of required while keeping its type, so optional and nullable stay distinguishable — a distinction most hand-written schemas blur.

Nested objects are never inlined: each becomes its own entry under definitions and is referenced with a $ref, so the schema stays flat and the definitions are reusable from other schemas. Arrays are type array with an items subschema pointing at the element's $ref, which is why one Item definition covers every element. A single-element array still produces a full definition, but an empty array degrades to an empty items object that matches anything at all — replace empty arrays in the sample before trusting the result.

Help

Frequently asked questions

Everything you need to know about the JSON to JSON Schema.

01How do I generate JSON Schema classes from JSON?

Paste a representative document — JSON or XML, the format is detected automatically — and press Convert. A real API response works best. Nested objects become their own JSON Schema types, arrays become "type": "array" of Item, and the result downloads as Root.json.

02What does the generated JSON Schema code include?

Instead of code, this target infers a JSON Schema document: types, required properties, and nested definitions derived from your sample — the contract your payload implies, made explicit and validatable.

03How do I use the generated JSON Schema code in my project?

Feed the document to any draft-06-compatible validator: Ajv in JavaScript (ajv.compile(schema)), jsonschema in Python, everit or networknt in Java. The top level points at definitions/Root through $ref, every object sets additionalProperties to false, and every property seen in the sample is listed as required — loosen those two if you want lenient validation of optional fields.

04How accurate is a schema inferred from one sample?

It captures exactly what the sample exhibits — fields present, types observed. Optional fields that happen to be absent or null in the sample won't be inferred; paste multiple representative samples merged into an array for tighter inference, then hand-tune requireds.

Keep working

Related tools

Learn the format

Related guides

All guides →