FormatterHQ

JSON to JSON Schema Generator

Infer a JSON Schema from example data. Each object shape becomes a definition with types, required properties and formats such as date-time.

Input JSON
Output JSON
Ready.

How to use the JSON to JSON Schema

  1. Paste your JSON sample (ideally an array of several records) into the Input editor, or use Sample, Upload file or Load URL.
  2. Set the Top-level class name; it becomes the name of the root definition.
  3. Press Generate to infer the schema.
  4. Use Copy or Download above the output panel to take the JSON Schema with you.

Infer a JSON Schema from example JSON

A JSON Schema describes what valid JSON looks like: which properties exist, their types, which are required and which formats strings follow. Writing one from scratch for a large payload takes time. This generator infers a JSON Schema from sample data using quicktype. Every distinct object shape becomes an entry under definitions, and the root refers to it with $ref. The output declares "$schema": "http://json-schema.org/draft-06/schema#".

Example

From the sample below (class name Task):

{
  "id": 42,
  "title": "Write docs",
  "done": false,
  "priority": 2.5,
  "tags": ["docs"],
  "owner": { "name": "Ada", "email": null },
  "due": "2026-10-01T09:00:00Z",
  "subtasks": [
    { "title": "Outline", "estimate": 2 },
    { "title": "Draft" }
  ]
}

the generator produces, among others, this definition:

"Subtask": {
    "type": "object",
    "additionalProperties": false,
    "properties": {
        "title": { "type": "string" },
        "estimate": { "type": "integer" }
    },
    "required": ["title"],
    "title": "Subtask"
}

estimate is missing from one subtask, so it is not listed in required. In the Task definition, id is an integer, priority a number, owner a $ref to #/definitions/Owner, and due a string with "format": "date-time".

What the generator infers

From the sampleIn the schema
Whole numbers only"type": "integer"
Any decimal"type": "number"
ISO date-time strings"format": "date-time" (also date, time, uuid)
Nested objectsdefinitions entries referenced by $ref
Keys present in every objectlisted in required
Values that are sometimes nullanyOf with {"type": "null"}

Every object is marked "additionalProperties": false, which means extra keys are rejected by validators. That is strict but useful: it catches typos in property names. Relax it by removing the line or setting it to true if your API may add fields.

Top-level arrays

When the sample is an array, the root of the schema is "type": "array" with "items" pointing to a definition named after your class name plus Element. All array elements are merged into that one definition, so the more records you include, the more accurate the required lists and types become.

Refining the schema

A sample shows types, not rules. Consider adding:

  • minLength, maxLength and pattern for strings; minimum and maximum for numbers.
  • enum for fields with a fixed list of values, such as a status.
  • description for each property, which documentation tools display.
  • "format": "email" or "uri" where applicable.

Draft-06 schemas are accepted by the common validators such as Ajv, and can be upgraded to newer drafts (2019-09 and 2020-12) mostly by renaming definitions to $defs and updating $schema.

Uses for a generated schema

  • Validating request bodies in an API, or configuration files in CI.
  • Editor autocompletion: VS Code validates JSON files against a schema referenced with a "$schema" property in the file, or mapped to file patterns with the json.schemas setting, and then suggests property names as you type.
  • Test fixtures: validating sample payloads in unit tests catches accidental changes to an API's response shape.
  • Documentation and contract tests between services.
  • Generating code in other languages from the schema.

For TypeScript-native validation, see JSON to Zod. Validate the input first with the JSON Validator, and pretty print the schema with the JSON Formatter if you edit it by hand. Everything runs in your browser.

Frequently asked questions

Which JSON Schema draft does the generator produce?
Draft-06, declared in the $schema property. Common validators support it, and upgrading to 2020-12 mainly means renaming definitions to $defs and changing the $schema URL.
Why does my schema reject extra properties?
Each object is generated with additionalProperties set to false, so unexpected keys fail validation. Remove that line or set it to true to allow them.
How are required properties determined?
A property is required when it appears in every object of that shape in your sample. Keys missing from any object become optional.
Can I generate a schema from several examples?
Paste them as a JSON array. All elements are merged, which gives more accurate required lists and types.
Does it detect enums?
No. Strings are kept as strings. Add an enum list by hand for fields with a fixed set of values.

Last updated September 26, 2026

Related tools

XML to JSON Schema Generate JSON Schema a JSON Schema document from a XML sample instantly, with nested types detected automatically. JSON to Kotlin Generate Kotlin data classes from a JSON sample instantly, with nested types detected automatically. JSON to Laravel Model & Migration Generate a Laravel Eloquent model ($fillable, casts, relations) and a matching migration from a sample JSON record. JSON to Mongoose Schema Generate a Mongoose schema and model from a sample JSON document, detecting Date, ObjectId, arrays and nested objects. JSON to Objective-C Generate Objective-C classes with properties from a JSON sample instantly, with nested types detected automatically. JSON to PHP Generate PHP classes with typed properties from a JSON sample instantly, with nested types detected automatically. JSON to Pike Generate Pike classes from a JSON sample instantly, with nested types detected automatically. JSON to Python Generate Python dataclasses with type hints from a JSON sample instantly, with nested types detected automatically. JSON to Ruby Generate Ruby Dry::Struct classes from a JSON sample instantly, with nested types detected automatically. JSON to Rust Generate Rust structs with Serde derives from a JSON sample instantly, with nested types detected automatically. JSON to Scala Generate Scala case classes from a JSON sample instantly, with nested types detected automatically. JSON to Swift Generate Swift Codable structs from a JSON sample instantly, with nested types detected automatically.