> ## Documentation Index
> Fetch the complete documentation index at: https://docs.dottxt.ai/llms.txt
> Use this file to discover all available pages before exploring further.

# Quicktype

> Infer JSON Schema from sample JSON using Quicktype.

[Quicktype](https://quicktype.io/) infers JSON Schema from sample JSON data. It works well when you have example outputs but no model or schema definition yet.

Quicktype currently emits draft-06 JSON Schema. That reflects the tool's output format, not a recommendation to target draft-06 in new hand-written schemas.

## Install

```bash theme={"theme":{"light":"vitesse-light","dark":"vitesse-dark"}}
npm install -g quicktype
```

## Basic usage

Given a sample JSON file:

<CodeGroup>
  ```json sample.json theme={"theme":{"light":"vitesse-light","dark":"vitesse-dark"}}
  {
    "name": "Alice Johnson",
    "email": "alice@acme.com",
    "role": "Product Manager"
  }
  ```

  ```bash CLI theme={"theme":{"light":"vitesse-light","dark":"vitesse-dark"}}
  quicktype --src sample.json --src-lang json --lang schema -o contact.schema.json
  ```

  ```json JSON Schema theme={"theme":{"light":"vitesse-light","dark":"vitesse-dark"}}
  {
    "$ref": "#/definitions/Sample",
    "definitions": {
      "Sample": {
        "type": "object",
        "properties": {
          "name": { "type": "string" },
          "email": { "type": "string" },
          "role": { "type": "string" }
        },
        "required": ["email", "name", "role"],
        "additionalProperties": false,
        "title": "Sample"
      }
    }
  }
  ```
</CodeGroup>

Quicktype infers types from the values it sees and wraps everything in a `$ref` + `definitions` structure. The type name (`Sample`) is derived from the filename. Unlike Genson, Quicktype sets `additionalProperties: false` by default.

## Multiple samples

Pass multiple samples to improve inference. Quicktype merges them and detects optional fields: a field missing from some samples becomes non-required:

<CodeGroup>
  ```json sample1.json theme={"theme":{"light":"vitesse-light","dark":"vitesse-dark"}}
  {"name": "Alice", "email": "alice@acme.com", "phone": "+1-555-0100"}
  ```

  ```json sample2.json theme={"theme":{"light":"vitesse-light","dark":"vitesse-dark"}}
  {"name": "Bob", "email": "bob@acme.com"}
  ```

  ```bash CLI theme={"theme":{"light":"vitesse-light","dark":"vitesse-dark"}}
  quicktype --src sample1.json --src sample2.json --src-lang json --lang schema
  ```

  ```json JSON Schema theme={"theme":{"light":"vitesse-light","dark":"vitesse-dark"}}
  {
    "$ref": "#/definitions/TopLevel",
    "definitions": {
      "TopLevel": {
        "type": "object",
        "properties": {
          "name": { "type": "string" },
          "email": { "type": "string" },
          "phone": { "type": "string" }
        },
        "required": ["email", "name"],
        "additionalProperties": false,
        "title": "TopLevel"
      }
    }
  }
  ```
</CodeGroup>

`phone` is correctly detected as optional since it only appears in one sample. When multiple source files are provided, the type is named `TopLevel` instead of being derived from a filename.

## Nested objects

Quicktype extracts nested objects into separate definitions and references them via `$ref`:

<CodeGroup>
  ```json nested.json theme={"theme":{"light":"vitesse-light","dark":"vitesse-dark"}}
  {
    "name": "Alice",
    "address": {
      "street": "123 Main St",
      "city": "Springfield",
      "country": "US"
    }
  }
  ```

  ```bash CLI theme={"theme":{"light":"vitesse-light","dark":"vitesse-dark"}}
  quicktype --src nested.json --src-lang json --lang schema
  ```

  ```json JSON Schema theme={"theme":{"light":"vitesse-light","dark":"vitesse-dark"}}
  {
    "$ref": "#/definitions/Nested",
    "definitions": {
      "Nested": {
        "type": "object",
        "properties": {
          "name": { "type": "string" },
          "address": { "$ref": "#/definitions/Address" }
        },
        "required": ["address", "name"],
        "additionalProperties": false,
        "title": "Nested"
      },
      "Address": {
        "type": "object",
        "properties": {
          "street": { "type": "string" },
          "city": { "type": "string" },
          "country": { "type": "string" }
        },
        "required": ["city", "country", "street"],
        "additionalProperties": false,
        "title": "Address"
      }
    }
  }
  ```
</CodeGroup>

The key name `address` is PascalCased to `Address` for the definition.

## Arrays

Quicktype infers item types from array contents:

<CodeGroup>
  ```json arrays.json theme={"theme":{"light":"vitesse-light","dark":"vitesse-dark"}}
  {
    "question": "What is your favorite color?",
    "options": ["red", "green", "blue"],
    "tags": ["survey", "color"]
  }
  ```

  ```bash CLI theme={"theme":{"light":"vitesse-light","dark":"vitesse-dark"}}
  quicktype --src arrays.json --src-lang json --lang schema
  ```

  ```json JSON Schema theme={"theme":{"light":"vitesse-light","dark":"vitesse-dark"}}
  {
    "$ref": "#/definitions/Arrays",
    "definitions": {
      "Arrays": {
        "type": "object",
        "properties": {
          "question": { "type": "string" },
          "options": {
            "type": "array",
            "items": { "type": "string" }
          },
          "tags": {
            "type": "array",
            "items": { "type": "string" }
          }
        },
        "required": ["options", "question", "tags"],
        "additionalProperties": false,
        "title": "Arrays"
      }
    }
  }
  ```
</CodeGroup>

Quicktype does not add `minItems` or `maxItems`; add those manually. See [Bounded Arrays](/json-schema/bounded-arrays).

## Arrays of objects

When arrays contain objects, Quicktype extracts the item schema into a separate definition, singularizing the field name:

<CodeGroup>
  ```json array_objects.json theme={"theme":{"light":"vitesse-light","dark":"vitesse-dark"}}
  {
    "contacts": [
      {"name": "Alice", "email": "alice@acme.com"},
      {"name": "Bob", "email": "bob@acme.com"}
    ]
  }
  ```

  ```bash CLI theme={"theme":{"light":"vitesse-light","dark":"vitesse-dark"}}
  quicktype --src array_objects.json --src-lang json --lang schema
  ```

  ```json JSON Schema theme={"theme":{"light":"vitesse-light","dark":"vitesse-dark"}}
  {
    "$ref": "#/definitions/ArrayObjects",
    "definitions": {
      "ArrayObjects": {
        "type": "object",
        "properties": {
          "contacts": {
            "type": "array",
            "items": { "$ref": "#/definitions/Contact" }
          }
        },
        "required": ["contacts"],
        "additionalProperties": false,
        "title": "ArrayObjects"
      },
      "Contact": {
        "type": "object",
        "properties": {
          "name": { "type": "string" },
          "email": { "type": "string" }
        },
        "required": ["email", "name"],
        "additionalProperties": false,
        "title": "Contact"
      }
    }
  }
  ```
</CodeGroup>

The field `contacts` produces a definition named `Contact` (singular).

## Type inference across samples

When multiple samples expose different field sets, Quicktype correctly distinguishes required from optional and infers `integer` vs `number`:

<CodeGroup>
  ```json mixed1.json theme={"theme":{"light":"vitesse-light","dark":"vitesse-dark"}}
  {"id": 1, "label": "first"}
  ```

  ```json mixed2.json theme={"theme":{"light":"vitesse-light","dark":"vitesse-dark"}}
  {"id": 2, "label": "second", "score": 0.95}
  ```

  ```bash CLI theme={"theme":{"light":"vitesse-light","dark":"vitesse-dark"}}
  quicktype --src mixed1.json --src mixed2.json --src-lang json --lang schema
  ```

  ```json JSON Schema theme={"theme":{"light":"vitesse-light","dark":"vitesse-dark"}}
  {
    "$ref": "#/definitions/TopLevel",
    "definitions": {
      "TopLevel": {
        "type": "object",
        "properties": {
          "id": { "type": "integer" },
          "label": { "type": "string" },
          "score": { "type": "number" }
        },
        "required": ["id", "label"],
        "additionalProperties": false,
        "title": "TopLevel"
      }
    }
  }
  ```
</CodeGroup>

`id` (whole numbers) is typed as `integer` while `score` (decimal) is typed as `number`. `score` is optional since it only appears in one sample.

## Limitations

Quicktype infers structure and types but does not add semantic constraints. The generated schema will not include:

* `enum` values
* `minLength`, `maxLength`, or `pattern` for strings
* `minItems`, `maxItems` for arrays
* `description` on fields or the schema

It also uses draft-06 and wraps every type in `$ref` + `definitions` rather than the more modern `$defs`.

The output is a starting point. Tighten it by adding constraints manually or follow [Improve your schema](/json-schema/improve-your-schema).
