PureDevTools

JSON Schema Generator

Paste a JSON sample and instantly generate a JSON Schema draft-07 — types, required fields, and string formats inferred automatically

All processing happens in your browser. No data is sent to any server.
JSON Schema (draft-07)

Generated JSON Schema draft-07 will appear here.

You have a working API that returns JSON, and now you need a JSON Schema for documentation, request validation, or TypeScript type generation. Writing a schema by hand for a 50-field nested response means specifying type, properties, required, items, and format for every field — a 200-line schema for a 50-line JSON. You could generate it from a sample response instead.

Why This Generator (Not the JSON Schema Validator)

PureDevTools has a JSON Schema Validator for validating data against an existing schema. This tool generates schemas from sample data — paste a JSON example, get a JSON Schema (draft-07) with inferred types, required fields, and string formats. Use this to create the schema; use the validator to enforce it.

What Is a JSON Schema?

A JSON Schema is a declarative vocabulary that describes the structure and constraints of a JSON document. Defined by JSON Schema draft-07 (the most widely supported version), it lets you specify which fields are required, what data type each field accepts, and additional format constraints like email, uri, or date.

JSON Schemas are widely used for:

How the Generator Works

Paste any valid JSON — an object, an array, a nested structure — and the tool infers a JSON Schema draft-07 that would validate it:

  1. Type inference: Each field’s JavaScript type (string, number, integer, boolean, null, object, array) is mapped to the corresponding JSON Schema type. Whole numbers like 42 become "type": "integer" while decimals like 3.14 become "type": "number".
  2. Required fields: Every key present in a sample object is added to the required array, because it appears in your data.
  3. String format detection: String values are matched against common patterns:
    • email — e.g. "alice@example.com"
    • uri — e.g. "https://example.com/path"
    • date — ISO 8601 date, e.g. "2024-03-15"
    • date-time — ISO 8601 datetime, e.g. "2024-03-15T10:30:00Z"
  4. Nested objects: Recursively generates properties for nested objects.
  5. Arrays of objects: Merges schemas across all array items to produce a unified items schema. Properties present in every item are marked required; properties that only appear in some items remain optional.
  6. Mixed-type arrays: Produces an anyOf list of inferred types for heterogeneous arrays.

Configurable Options

Include Examples

When enabled, each scalar property gains an "examples" array containing the sampled value. This is useful when publishing schemas via Swagger or JSON Schema documentation tools, because the example value shows up alongside the field description.

Add Descriptions

When enabled, every property gets a "description" string and the root schema gets a "title". Descriptions are generated from the field name and detected format. You can edit these descriptions after copying the schema to add business context.

Working with the Generated Schema

The generated schema is a starting point, not a final product. After copying, you will typically want to:

Common Use Cases for Developers

OpenAPI / Swagger schemas — paste an example API response and get an instant schema component you can paste into your components/schemas section.

TypeScript code generation — feed the schema to json-schema-to-typescript (npx json-schema-to-typescript) to generate TypeScript interfaces for your data model.

Config file validation — VS Code’s json.schemas setting accepts JSON Schema definitions, enabling IntelliSense and validation for your own configuration files.

Database seed validation — validate seed data files before loading them into your database by running them through an Ajv-based validator with the generated schema.

API contract testing — generate schemas from real API responses, then add them to Pact or Dredd to detect when the API breaks the expected shape.

Frequently Asked Questions

Q: What is draft-07 and why not draft 2020-12? A: JSON Schema draft-07 (released 2018) is the most widely supported version across validators, code generators, and OpenAPI tooling. Draft 2020-12 added features like $dynamicRef and unevaluatedProperties, but most tools have not yet fully adopted it. Draft-07 is the safest choice for maximum compatibility.

Q: Why does every field become required? A: The generator can only observe the data you provide. If a key exists in your sample, it was present in that request — so the tool marks it required. Remove fields from required that are optional in your real schema.

Q: How does type inference handle null? A: If a value is null, the property gets "type": "null". In arrays of objects where a field is null in some items but a string in others, the tool generates "anyOf": [{"type": "string"}, {"type": "null"}] to allow both.

Q: Can I generate schemas from arrays of objects? A: Yes. When the root JSON value is an array of objects, the tool merges all object schemas into one representative items schema. Properties that appear in every object are required; properties that only appear in some objects are optional.

Q: Is my JSON sent to a server? A: No. All processing happens in your browser using JavaScript. No JSON data, schema output, or metadata is transmitted anywhere. Your data stays private.

Q: Can I validate JSON against the generated schema? A: Yes — use the JSON Schema Validator tool on this site. Paste your JSON Schema and your data to check if it validates correctly.

Related Tools

More JSON Tools