DevToolsmith

JSON to JSON Schema Generator

Paste a JSON sample to generate a JSON Schema (draft 2020-12 or draft 7). Types, required keys, nullable values and formats like email, uri and date-time are inferred automatically.

Runs 100% in your browser — nothing is uploaded

JSON
Tip: drop a file here361 chars · 361 bytes · 14 lines
JSON Schema
1,427 chars · 1,427 bytes · 84 lines

Tip: paste an array of several objects — keys missing from some of them become optional (left out of required).

Example

JSON input
[
  {
    "id": 1,
    "email": "ada@example.com",
    "role": "admin",
    "signedUpAt": "2026-01-05T10:00:00Z"
  },
  {
    "id": 2,
    "email": "grace@example.com",
    "role": "editor",
    "signedUpAt": "2026-02-11T08:30:00Z",
    "nickname": null
  }
]
Generated schema
{
  "$schema": "https://json-schema.org/draft/2020-12/schema",
  "type": "array",
  "items": {
    "type": "object",
    "properties": {
      "id": {
        "type": "integer"
      },
      "email": {
        "type": "string",
        "format": "email"
      },
      "role": {
        "type": "string"
      },
      "signedUpAt": {
        "type": "string",
        "format": "date-time"
      },
      "nickname": {
        "type": "null"
      }
    },
    "required": [
      "id",
      "email",
      "role",
      "signedUpAt"
    ]
  }
}
  • nickname only appears in one object, so it isn’t in required.
  • email and signedUpAt got format: email and format: date-time.
  • role looks like a fixed set of values; consider adding "enum": ["admin", "editor"] by hand.

Validate data against the schema

Click Validate with it to open the schema and your JSON in the JSON Schema Validator, or validate in code:

JavaScript (Ajv)
// npm install ajv ajv-formats
import Ajv2020 from 'ajv/dist/2020';
import addFormats from 'ajv-formats';

const ajv = new Ajv2020({ allErrors: true });
addFormats(ajv); // without this, "format" is not checked

const validate = ajv.compile(schema);
if (!validate(data)) console.log(validate.errors);
Python
# pip install jsonschema
from jsonschema import Draft202012Validator

validator = Draft202012Validator(schema, format_checker=Draft202012Validator.FORMAT_CHECKER)
for error in validator.iter_errors(data):
    print(error.json_path, error.message)

Where JSON Schema is used

  • API validation: reject bad request bodies before they reach your code (Fastify uses it natively).
  • OpenAPI: request and response models in OpenAPI 3.1 are JSON Schema 2020-12.
  • Editor autocomplete: add "$schema": "./config.schema.json" to a JSON config file and VS Code validates it and suggests keys as you type.
  • LLM structured output: function calling and structured output APIs take a JSON Schema for the response.

Prefer types in code? Generate Zod schemas, Pydantic models or TypeScript interfaces from the same JSON.

Frequently asked questions

How do I generate a JSON Schema from JSON?

Paste a sample JSON document into the tool above. It infers a schema with the type of every value, a properties entry for every key, a required list of keys present in all samples, and formats such as email, uri, uuid and date-time. Use an array of several objects to get a more accurate result.

Which draft should I use?

Use 2020-12, the current version, unless a tool requires an older one. Draft 7 is still the most widely supported, for example in some IDEs and older validators, and OpenAPI 3.0 uses a variant of it. OpenAPI 3.1 is fully aligned with 2020-12.

How is “required” decided?

A key is required when it appears in every sample object. If you paste a single object, every key is required; paste an array of several representative objects and keys that are missing from some of them are left out of required.

Why does my validator ignore “format”?

Since draft 2019-09, format is an annotation by default: validators record it but don’t reject invalid values unless format checking is turned on. In Ajv, install ajv-formats and call addFormats(ajv). In Python’s jsonschema, pass a format_checker.

Is the generated schema complete?

It describes the structure of your sample, which is the tedious part. You will usually want to tighten it by hand: add enum for fixed values, minimum and maximum for numbers, minLength or pattern for strings, and descriptions for documentation.