Skip to content
← Blog
HomeBlogJSON Schema Generator Guide

JSON Schema Generator: Complete Guide to Inference & Exports

By Bill Crawford ยท March 2, 2026 ยท 8 min read  ยท  Last updated March 02, 2026

In This Guide

  1. What Is JSON Schema?
  2. Why Generate Schema from JSON?
  3. How Schema Inference Works
  4. Inference Settings Explained
  5. Export Formats: TS, Zod, C#, SQL
  6. Edge Cases and Warnings
  7. Best Practices
  8. FAQ

๐Ÿ”ง Try the tool: Generate JSON Schema from any JSON data instantly โ€” with TypeScript, Zod, C#, and SQL exports.

Open JSON Schema Generator

What Is JSON Schema?

JSON Schema is a declarative vocabulary for describing the structure of JSON data. It defines which fields an object should have, what types those fields can be, whether they are required, and what constraints apply โ€” like string formats, numeric ranges, or array item types.

The standard is maintained by the JSON Schema organization and has gone through several draft versions. Draft 2020-12 is the latest and is recommended for new projects. Older drafts (2019-09 and Draft 07) remain widely used in existing toolchains, particularly in OpenAPI 3.0 specifications which rely on Draft 07.

A simple JSON Schema for a user object looks like this:

{
  "$schema": "https://json-schema.org/draft/2020-12/schema",
  "type": "object",
  "properties": {
    "id": { "type": "integer" },
    "name": { "type": "string" },
    "email": { "type": "string", "format": "email" }
  },
  "required": ["id", "name", "email"]
}

This schema says: the root is an object with three properties โ€” id (an integer), name (a string), and email (a string with email format). All three are required.

Why Generate Schema from JSON?

Writing JSON Schema by hand is tedious. A moderately complex API response with nested objects and arrays can produce a schema hundreds of lines long. Generating the schema from sample data eliminates this manual work.

Common use cases for generated schemas:

How Schema Inference Works

Schema inference examines each value in the JSON and determines its type, then builds a schema recursively. Here is how the generator handles each JSON type:

Primitives

Strings, numbers, booleans, and null are straightforward: the generator emits "type": "string", "type": "number" (or "integer" if the value is a whole number and integer detection is on), "type": "boolean", or "type": "null".

String Format Detection

When format detection is enabled, the generator checks string values against patterns for common formats: email addresses, URIs (http/https), ISO 8601 date-time strings, and UUIDs. If a match is found, a "format" keyword is added to the schema โ€” for example, "format": "email".

Objects

For each object, the generator collects all keys and recursively infers a schema for each value. The required array depends on the selected mode: "all" marks every observed key as required, "none" omits the required array entirely, and "heuristic" marks a key as required only if its value is non-null, non-empty-string, non-empty-array, and non-empty-object.

Arrays

Arrays are where inference gets interesting. The generator needs to produce a single items schema that describes all elements. Three modes are available:

When merging two object schemas, the generator takes the union of property keys. If a key exists in one schema but not the other, it becomes optional (removed from required). If two values for the same key have different types, the generator produces a type union โ€” for example, "type": ["string", "integer"].

Inference Settings Explained

SettingOptionsEffect
Schema Draft2020-12, 2019-09, 07Sets the $schema URI. Most modern tools support 2020-12.
Required FieldsAll / None / HeuristicControls which properties appear in the required array.
Null HandlingNullable / IgnoreNullable adds "null" to type unions. Ignore drops null if another type exists.
Array ModeUnion / First / StrictHow array item schemas are combined.
Integer DetectionOn / OffWhole numbers become "integer" instead of "number".
Format DetectionOn / OffDetects email, URI, date-time, UUID formats in strings.
Additional Propertiestrue / falseWhen false, the schema rejects properties not listed in properties.
Generate TitleOn / OffAdds a "title" keyword to the root schema.

Export Formats

TypeScript Types

The TypeScript export maps the schema to type definitions. Objects become interface-like types with required and optional properties. Arrays become T[]. Union types use |. Nullable fields become string | null. This gives you type safety in TypeScript projects without writing types manually.

type Root = {
  id: number;
  name: string;
  email?: string | null;
  tags: string[];
};

Zod Validation Schemas

Zod is a TypeScript-first schema validation library. The Zod export produces a runtime validator that matches the inferred schema. This is useful when you need both compile-time types and runtime validation โ€” for example, validating API responses in a Next.js application.

import { z } from "zod";

export const Root = z.object({
  id: z.number().int(),
  name: z.string(),
  email: z.string().email().nullable().optional(),
  tags: z.array(z.string()),
});

C# POCO Classes

The C# export generates plain old CLR objects (POCOs) suitable for System.Text.Json or Newtonsoft.Json deserialization. Nested objects become separate classes. Arrays become List<T>. Nullable types use the ? suffix.

SQL DDL

The SQL export generates a CREATE TABLE statement from flat object properties. Strings map to NVARCHAR(255), integers to INT, numbers to DECIMAL(18,6), booleans to BIT, and date-time strings to DATETIME2. Nested objects and arrays are stored as NVARCHAR(MAX) with a JSON comment. This is most useful for quick prototyping of SQL Server tables from JSON data.

Edge Cases and Warnings

The generator shows warnings in the following situations:

๐Ÿ’ก Tip: For the most accurate schema, provide a JSON sample that includes all possible field variations โ€” including null values, optional fields, and different array item shapes.

Best Practices

Frequently Asked Questions

What is JSON Schema and why generate it from JSON?

JSON Schema is a vocabulary for annotating and validating JSON data. Generating it from a sample avoids hand-writing verbose schema definitions โ€” the tool infers types, required fields, and formats automatically.

How does the generator handle arrays with different object shapes?

In union mode, the generator merges all item schemas by taking the union of properties and the intersection of required fields. Fields that appear in some items but not others become optional. A warning is shown listing the inconsistent fields.

Can I use the generated TypeScript types in production?

The generated types are a strong starting point. Review them for edge cases โ€” particularly union types and optional fields โ€” and add custom validation logic where needed. Consider using the Zod output for runtime validation alongside the TypeScript types.

Which JSON Schema draft should I use?

Draft 2020-12 is the latest and recommended for new projects. Use Draft 07 if your toolchain (e.g., older validators, OpenAPI 3.0, or certain code generators) requires it. Draft 2019-09 is a middle ground but is less commonly targeted.

๐Ÿ”ง Ready to generate? Paste your JSON and get a schema instantly.

Open JSON Schema Generator
BC
Bill Crawford
Founder, Data Conversion Center

Bill builds browser-based developer tools that prioritize privacy and speed. With a background in data engineering and API design, he focuses on making common developer tasks faster and more accessible.

Related Tools

Related Articles