Quick access

Saved in this browser. Sign in to keep it on all your devices.

JSON Schema Generator

Generate JSON Schema from sample JSON data.

Sample JSON
JSON Schema

Quick Examples

Supported Types

string number integer boolean null array object
Version 1.1 Updated What's new

Release notes

  1. v1.1 Latest
    • Added an in-depth guide below the tool, written from what the tool actually does.
    • Fixed the generated schema for nested objects, arrays and string formats such as email and date.

About the JSON Schema Generator

A JSON Schema describes the shape of JSON data: which fields exist, their types, and which are required. It is used to validate API requests and to document data formats.

How to use it

  1. 1 Paste a sample JSON document.
  2. 2 Generate the schema.
  3. 3 Review the required fields and types, then copy the schema.

Frequently asked questions

What is JSON Schema used for?

To validate data automatically, generate forms and documentation, and describe request and response bodies in OpenAPI specs.

Is the generated schema final?

It is a starting point. A single sample cannot show every rule, so add limits like minLength, enum values, or formats by hand.

Which fields are marked as required?

Every field in your sample is marked required, except that a field missing from some items of an array is left optional. Remove any others that are optional in real data, or switch Required off.

What is inferred from a sample

The generator walks your JSON and records what it finds, producing draft-07 output:

{"age": 30}

{
  "$schema": "http://json-schema.org/draft-07/schema#",
  "type": "object",
  "properties": { "age": { "type": "integer" } },
  "required": ["age"]
}

Whole numbers become integer and others become number. Objects are followed to any depth, and a top-level array is handled the same way as a top-level object.

Arrays are compared item by item

Every element of an array is inspected, not just the first. If one item has a note field and another does not, note appears in properties but stays out of required. If one item has a whole number where another has a decimal, the field becomes number. Mixed types produce a list such as ["integer", "string"].

So the best sample is an array with several realistic records, including ones with optional fields left out. A single perfect record teaches the generator nothing about what can vary.

Formats are judged from values

A format is added only when the value itself looks right: email, date, date-time, uuid, uri or ipv4. Field names are ignored, so an "id" holding "abc" stays a plain string. Be aware that most validators treat format as an annotation by default and do not reject a bad value unless the option is switched on. In Ajv that requires the separate ajv-formats package.

What to add by hand

A sample cannot reveal the rules behind the data. Before relying on the result, consider adding:

  • enum for a field limited to fixed values, such as a status.
  • minimum and maximum for numbers with known bounds.
  • minLength, maxLength or pattern for strings.
  • additionalProperties: false if unknown fields should be rejected.
  • A null type alongside the original, for any field that can be empty.

Without additionalProperties, a schema allows extra keys, so a typo like "emial" passes as long as the required fields are also present. Test the finished schema against both good and deliberately bad records.