DevPik Logo

JSON Schema Generator

Generate a JSON Schema from sample JSON data with auto-detection of types, format patterns (email, UUID, date, IPv4), required fields, and enum values. Supports Draft 2020-12 and Draft-07 plus validation mode.

Why Use JSON Schema Generator?

Writing a JSON Schema by hand for an existing API is painful — every nested field, every optional property, every format constraint has to be specified by hand. This generator takes a sample payload and produces a schema that covers 80% of what you need in one click. From there, you tighten the output by hand (adding `minLength`, `enum`, better descriptions). Useful for adding request validation to Express/Fastify/Hono endpoints, generating OpenAPI docs, or producing Pydantic/Zod types from an existing JSON fixture.

How to Use JSON Schema Generator

  1. Paste your sample JSON data into the left panel. The schema generates in real-time as you type.
  2. Customize options: choose Draft 2020-12 or Draft-07, toggle format detection (email, URI, UUID, date), required fields, and enum detection.
  3. Add an optional title and description for your schema using the input fields above the panels.
  4. Switch to Validate mode to paste a JSON Schema and validate any JSON data against it.
  5. Copy the generated schema or download it as a .json file.

Worked Examples

Generate schema from a user object

Input
{ "id": 1, "email": "jane@example.com", "signup": "2026-01-15" }
Output
A schema with `id`: integer, `email`: string format `email`, `signup`: string format `date`. All three marked `required`.

Format detection recognizes email and ISO date patterns automatically.

Schema merges across an array

Input
[ { "id": 1, "name": "A" }, { "id": 2, "name": "B", "tag": "beta" } ]
Output
Array item schema: `id` + `name` required, `tag` optional (appeared in only 1 of 2 objects).

Required inference looks at which fields are present in *every* item.

Validate a payload against a schema

Input
Switch to Validate mode • paste schema + sample JSON
Output
Errors listed with JSON paths, e.g., `/email: format "email" violated`

Great for catching malformed test fixtures or bad API responses.

About JSON Schema Generator

JSON Schema Generator is a free online tool that auto-generates a JSON Schema from any sample JSON data. JSON Schema is a powerful vocabulary for annotating and validating JSON documents — it's used for API validation, documentation generation, code generation, and automated testing. This tool analyzes your JSON structure recursively: detecting types (string, number, integer, boolean, null, array, object), identifying common string formats (email, URI, UUID, date, date-time, IPv4, IPv6), marking required fields, handling homogeneous and heterogeneous arrays, and merging schemas from multiple array objects. Output supports both Draft 2020-12 (latest) and Draft-07 (widely supported). The built-in Validate mode lets you test JSON data against any schema. All processing runs 100% client-side — your data stays private.

Troubleshooting & Common Issues

Optional fields marked required

The generator looks at the sample — if every object in an array has a field, it's marked required. Supply more diverse examples (some with, some without the field) to get the correct optionality, or manually toggle `required` in the output.

Numbers inferred as `integer` when they should be `number`

The generator infers integer when all observed values are whole numbers. If the field *could* hold floats (e.g., `price`), either include a float in the sample or hand-edit `type` to `number`.

Schema validates but API still returns wrong shape

JSON Schema validates the shape of a payload but can't enforce business rules ("email must exist in users table"). For dynamic validation, add custom rules on top of schema validation, or use schema as the first-line filter only.

Draft 2020-12 schema rejected by older tooling

Many Go, Java, and Python libraries still target Draft-07. Switch the draft selector before exporting the schema. The core vocabulary is compatible — but a few keywords (`prefixItems`, `$dynamicRef`) are 2020-12-only.

Frequently Asked Questions

What is JSON Schema?

JSON Schema is a declarative language for describing the structure and validation constraints of JSON data. It specifies which properties are allowed, their types, which are required, string formats, array item types, and more. It's used for API request/response validation, form generation, documentation, and code generation.

How do I generate a JSON Schema from JSON?

Paste your sample JSON data into the left panel and the tool instantly generates a matching schema. The generator analyzes types, detects patterns like email and UUID formats, marks required fields, and handles nested objects and arrays. You can customize the output by toggling format detection, required fields, and enum detection.

What is the difference between Draft 2020-12 and Draft-07?

Draft 2020-12 is the latest JSON Schema specification with improved vocabulary system, dynamic references, and cleaner semantics. Draft-07 is older but has wider tooling support. For most use cases, Draft 2020-12 is recommended. This tool supports both — select your preferred draft from the dropdown.

Can I validate JSON against a schema?

Yes! Switch to Validate mode using the button in the toolbar. Paste your JSON data in the left panel and your JSON Schema in the right panel, then click Validate. The tool checks types, required fields, enum values, and formats, reporting all validation errors with JSON paths.

What string formats does the tool detect?

When format detection is enabled, the tool recognizes: email addresses, URIs (http/https URLs), date-time (ISO 8601), dates (YYYY-MM-DD), times, UUIDs, IPv4 addresses, and IPv6 addresses. These are added as "format" keywords in the generated schema.

How does the tool handle arrays?

The generator inspects all array items to determine the schema. Homogeneous arrays (all items same type) get a single items schema. Arrays of objects are merged — all property schemas are combined and required fields are detected based on which keys appear in every object. Heterogeneous arrays use oneOf.

Is my data safe with this tool?

Yes. This JSON Schema generator runs 100% client-side in your browser. No JSON data is ever sent to any server. Your data stays completely private on your device.

Related Tools

Was this tool helpful?