JSON to Schema
JSON input
105 chars · 12 words · 6 linesPaste one or several samples — optional fields emerge across documents.
Schema format
4propsobjectroot2format hints

Generated JSON Schema

{
  "$schema": "https://json-schema.org/draft/2020-12/schema",
  "title": "User",
  "type": "object",
  "properties": {
    "id": {
      "type": "integer"
    },
    "email": {
      "type": "string",
      "format": "email"
    },
    "roles": {
      "type": "array",
      "items": {
        "type": "string"
      }
    },
    "createdAt": {
      "type": "string",
      "format": "date-time"
    }
  },
  "required": [
    "id",
    "email",
    "roles",
    "createdAt"
  ]
}

JSON to Schema

Build a validation schema from JSON samples in seconds. Paste one or more documents and get JSON Schema, Zod, Pydantic, OpenAPI, a NestJS DTO or a Prisma model — derived locally, never uploaded.

About this tool

What is it?
DataFormatter JSON to Schema is a free online tool that derives validation schemas from JSON samples — JSON Schema, Zod, Pydantic, OpenAPI or a NestJS DTO.
Who is it for?
Developers adding validation to a codebase who want an accurate schema derived directly from example payloads.
What makes DataFormatter's tool different?
It lets you supply multiple samples so it can learn which fields are optional, and everything runs locally with no upload.

Quick start

  1. Paste a JSON document (or several, to teach the inferrer about optional fields).
  2. Name the root model if you use Pydantic, NestJS or OpenAPI.
  3. Choose an output: JSON Schema, Zod, Pydantic, OpenAPI, NestJS DTO or Prisma.
  4. Copy or download the generated schema and drop it into your project.

What JSON to schema generates

  • JSON Schema — standard type, required, properties, items and format keywords.
  • Zod — z.object() chains with .email()/.uuid()/.datetime() validators.
  • Pydantic — typing-based BaseModel classes with field types and optional markers.
  • OpenAPI — component schema with nullable handling for optional properties.
  • NestJS DTO — class-validator decorators (@IsString, @IsEmail, @IsEnum…) on a TypeScript class.
  • Prisma — a model with scalar-list and Json types ready for your Prisma schema.

How to derive a schema online

  • Paste a sample document — the inference step summarizes the types first.
  • Provide several samples when fields are conditional, so they become optional.
  • Scan the format hints chip to see how many named formats were recognized.
  • Switch formats to compare the same model in each family of tools.
JSON sample
{ "id": 42, "email": "a@b.io" }
JSON Schema output
{
  "type": "object",
  "required": ["id", "email"],
  "properties": {
    "id": { "type": "integer" },
    "email": { "type": "string", "format": "email" }
  }
}

Who converts JSON to schema — and when

Adding runtime validation to TypeScript

Paste a response sample, generate the Zod schema, and use it at the API boundary to fail fast on malformed data.

Python backend contracts

Derive Pydantic models from a colleague's JSON so request bodies are validated with typing support in your editor.

Repository hygiene

Generate an OpenAPI or JSON Schema from fixture data so every consumer can validate against a single, documented contract.

Common issues

Field wrongly required

Why: Every observed key is required by default — a single sample hides optionality.

Fix: Paste a few representative documents so missing keys are detected and marked optional.

Arrays with mixed element types

Why: A heterogeneous array (numbers and strings together) has no single element type.

Fix: Keep arrays homogeneous, or wrap heterogeneous records as objects so each field keeps its type.

Format not detected

Why: Date-times without the T (e.g. space-separated) or padded/odd-shaped UUIDs fall back to plain string.

Fix: Normalize to ISO-8601 / standard UUID shape first, then regenerate.

Pro tips

  • Multiple samples beat one: unions and optionality only appear across documents.
  • Pairs with JSON-to-Code: schema for validation, types for compile-time safety.
  • JSON Diff is the perfect companion when your API contract evolves and you need to re-derive.
  • Because nothing is uploaded, you can generate schemas from real, sensitive payloads.

Frequently asked questions

How does JSON become a schema?

Your JSON is reduced to a type model (objects, arrays, scalars and named string formats like email, uuid, date or date-time), then that model is rendered as JSON Schema, Zod, Pydantic, an OpenAPI schema, a NestJS DTO, or a Prisma model.

Can it build a schema from several samples?

Yes. Paste multiple JSON documents one after another — each valid document is treated as a sample. Inference unions types across samples so fields that only appear sometimes become optional (or nullable where formats allow).

How are string formats detected?

Values get validated against common shapes: email addresses, UUIDs, ISO dates (YYYY-MM-DD), ISO date-times (YYYY-MM-DDTHH:mm…) and URLs. Formats appear as format: or pattern constraints in the output.

What does Zod support look like?

Generated Zod schemas use z.object, z.string(), z.number(), z.boolean(), z.array(), z.enum() for arrays of strings, z.email()/z.uuid() for recognized formats, and .optional() for fields missing from some samples.

Is my JSON uploaded?

Never. Schema generation runs entirely in your browser. This is the safe way to derive schemas for internal APIs or payloads containing real user data.

Which formats are exported?

JSON Schema (draft with standard keywords), Zod schema, Pydantic models for Python, an OpenAPI 3 component schema, a NestJS DTO class with class-validator decorators, and a Prisma model.

Related tools

Last reviewed September 2026 · DataFormatter team — this tool processes data locally in your browser.