JSON Schema Generator
Paste a JSON sample and instantly generate a JSON Schema draft-07 — types, required fields, and string formats inferred automatically
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:
- API documentation — tools like Swagger/OpenAPI use JSON Schema to describe request and response bodies
- Data validation — libraries such as Ajv, Zod, and Yup validate runtime data against a schema
- IDE autocompletion — VS Code uses JSON Schemas to provide autocomplete for JSON configuration files
- Code generation — tools like
json-schema-to-typescriptgenerate TypeScript interfaces directly from a schema
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:
- Type inference: Each field’s JavaScript type (
string,number,integer,boolean,null,object,array) is mapped to the corresponding JSON Schema type. Whole numbers like42become"type": "integer"while decimals like3.14become"type": "number". - Required fields: Every key present in a sample object is added to the
requiredarray, because it appears in your data. - 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"
- Nested objects: Recursively generates
propertiesfor nested objects. - Arrays of objects: Merges schemas across all array items to produce a unified
itemsschema. Properties present in every item are marked required; properties that only appear in some items remain optional. - Mixed-type arrays: Produces an
anyOflist 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:
- Remove over-constrained
required: If a field is optional in your real API, remove it fromrequired. - Relax
additionalProperties: false: The generator sets this tofalsefor safety. Change it totrueif the object should accept extra fields. - Add
minLength/maxLengthfor strings: Enforce length bounds on string fields. - Add
minimum/maximumfor numbers: Bound numeric fields to valid ranges. - Replace inferred formats with proper enums: If a string field holds one of a fixed set of values, replace
"type": "string"with"enum": ["active", "inactive", "pending"].
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.