JSON Schema Generator

A JSON Schema Generator analyses a sample JSON document and automatically produces a valid JSON Schema definition describing its structure, types, and required fields. Paste any JSON object or array, click Generate, and receive a ready-to-use schema you can refine and apply for validation, API documentation, or database contract enforcement.

S. Siddiqui

Edited by

S. SiddiquiFounder & Editor-in-Chief
Sources:MDN Web DocsW3CIETFUpdated Jun 2026

What Is a JSON Schema Generator?

A JSON Schema Generator is a browser-based tool that analyses a sample JSON document and automatically produces a JSON Schema definition that matches its structure. Instead of writing a schema by hand from scratch, you paste a representative JSON object or array, click Generate, and receive a valid schema that declares the type of every property, marks all present keys as required, and correctly handles nested objects, arrays of objects, and mixed-type arrays. You can then edit the generated schema to add constraints, remove fields, or adjust required property lists before using it for validation, API documentation, or data contract management.

JSON Schema itself is a declarative language for describing and validating JSON data. The specification is maintained by the JSON Schema organisation at json-schema.org and has gone through several published drafts, with Draft 2020-12 being the current stable version. A schema is itself a valid JSON document that uses a set of reserved keywords, such as type, properties, required, items, and $defs, to define the structure and constraints that conforming instances must satisfy. Writing one from scratch for a complex object with a dozen nested levels is tedious and error-prone. A generator eliminates that initial effort by inferring the structure directly from real data.

The tool processes your input entirely in the browser. Your JSON data is never sent to any server, so it is safe to use with real production records, customer data exports, or internal API responses.

JSON Schema is the foundation of many important tools in the developer ecosystem. The Swagger/OpenAPI 3.1 specification adopted JSON Schema Draft 2020-12 directly for defining API payloads. MongoDB supports JSON Schema for enforcing document structure in collections. AWS API Gateway validates incoming requests against JSON Schemas before passing them to Lambda functions. Postman uses JSON Schema in test assertions to verify that API responses match a defined contract. The ability to generate a schema rapidly from a real-world sample is therefore a practical time-saver for a wide range of development and data tasks.

How to Use the JSON Schema Generator

  1. Prepare a representative JSON sample. Choose a JSON document that contains all the fields you expect to appear in real usage, including optional fields you want documented in the schema. The more complete the sample, the more useful the generated schema. If your data comes from an API, paste a real response from a live or staging environment rather than a manually crafted example, as real responses reveal actual field names, nesting, and types accurately.
  2. Paste your JSON into the input panel. Copy the JSON text and paste it into the panel labelled "JSON Input" or "Sample JSON". The panel accepts any valid JSON: objects, arrays of objects, deeply nested structures, or arrays at the top level. Ensure the JSON is syntactically valid before proceeding; if it contains syntax errors the tool will report them rather than generating a schema.
  3. Click "Generate Schema". The tool analyses the structure, infers the type of each value (string, number, integer, boolean, null, object, or array), and constructs a schema that describes what it found. For nested objects, it recursively generates sub-schemas. For arrays, it inspects the first element to determine the item type.
  4. Review the generated schema in the output panel. Examine each property definition and confirm that the inferred types are correct. Pay particular attention to numeric fields: the generator distinguishes between "type": "integer" for whole numbers and "type": "number" for values with decimal places. If a field that should be a number appears as a string because the sample value was quoted, correct it manually.
  5. Edit the schema to add constraints and refine required fields. The generator marks every property present in the sample as required by default. Remove fields from the required array that are genuinely optional in your data model. Add keywords such as minLength, maxLength, pattern, minimum, maximum, format, and enum to enforce business rules beyond simple type checking.
  6. Copy and use the schema. Paste the finished schema into your codebase, your API specification, your database configuration, or the companion JSON Schema Validator tool to begin validating real data against it immediately.

Why Use This Tool

Writing a JSON Schema manually for any realistic data structure is time-consuming and prone to subtle errors. A generator converts hours of work into seconds, giving you a correct structural starting point that you then refine rather than build from nothing. The JSON Schema getting started guide illustrates how even a simple product schema requires careful attention to keywords, nesting, and required declarations. For a production API response with fifty fields across multiple levels, the manual approach is realistically error-prone in a way that automated generation is not.

API developers documenting endpoints

A developer building or documenting a REST API can paste a real response body into the generator to produce a schema for the response definition in their OpenAPI specification. This ensures the schema reflects what the API actually returns rather than what a developer believes it returns from memory. Swagger UI, Redoc, and other documentation tools then render that schema as a human-readable table of fields, making the generated schema do double duty as both a validation contract and living documentation.

Data engineers defining pipeline ingestion contracts

A data engineer who receives JSON feeds from partners or external systems can generate a schema from a sample delivery, review it, and use it to validate every subsequent delivery at the ingestion boundary. This pattern, sometimes called schema-on-read validation, catches upstream breaking changes before they propagate into a data warehouse. Generating the schema from a real sample rather than writing it from the partner's documentation ensures it reflects the actual format rather than the documented format, which are not always the same.

Backend developers adding MongoDB collection validation

MongoDB supports the $jsonSchema operator in collection validators to enforce document structure at the database level. A developer can generate a schema from a sample document, adapt it for MongoDB's dialect (which uses BSON type names rather than JSON Schema types), and apply it as a collection validator. This prevents application bugs from writing malformed documents to the database, making the schema act as a database-level integrity check.

QA engineers and technical writers creating data dictionaries

A QA engineer or technical writer who needs to document the structure of a system's data outputs can generate a schema from real output, add description fields to each property explaining its business meaning, and publish the annotated schema as a data dictionary. This approach produces documentation that is both human-readable and machine-executable, meaning the same document serves as reference material and as a runnable validation specification.

Real-World Use Cases

API developer building an OpenAPI specification from scratch

A full-stack developer at a software consultancy is tasked with creating the OpenAPI specification for an existing internal API that has no formal documentation. Rather than reading through controller code to reconstruct the response shapes, she runs a series of real API calls in Postman, copies the response bodies, and pastes them into the JSON Schema Generator to produce schemas for each endpoint. Within an afternoon she has draft schemas for all twelve endpoints, which she then adds descriptions to and integrates into the OpenAPI YAML. The resulting specification powers auto-generated Swagger UI documentation that the client team can use immediately.

Data engineer onboarding a new partner feed

A data engineer at a logistics company is integrating a new carrier partner's tracking event feed, which delivers JSON webhooks on every shipment status change. The carrier provides sample event payloads in their documentation. The engineer pastes three representative samples (a pick-up event, a transit event, and a delivery event) into the JSON Schema Generator, compares the outputs, and produces a unified schema that covers all three event types using oneOf with a discriminator on the eventType field. This schema becomes the validation gate for all incoming carrier webhooks, immediately flagging any delivery that arrives with a missing or mistyped required field.

Backend developer adding runtime validation to a Node.js service

A backend developer at a startup is building a Node.js service that processes orders received from a third-party e-commerce platform. The platform's API occasionally sends malformed payloads when customers use unsupported browser extensions during checkout. The developer generates a schema from a valid order object, adds minimum and maximum constraints to the quantity and price fields, marks the customer ID and line items as required, and integrates the schema with Ajv to validate every incoming order before processing begins. Malformed orders are rejected with a structured error response rather than causing uncaught exceptions in the order pipeline.

Technical writer producing a data contract for a cross-team API

A technical writer at a mid-sized SaaS company is responsible for maintaining the data contracts between the platform team's API and three consuming product teams. When the platform team ships a new API version, the writer pastes the new response samples into the JSON Schema Generator, adds description annotations for each field, and publishes the annotated schema in the company's internal developer portal. Each consuming team can validate their integration against the schema without waiting for a code-level review, reducing the integration cycle from several days to a single afternoon.

Common Mistakes and Troubleshooting

Using an incomplete or atypical sample

The generator can only infer types and structure from what is present in the sample you provide. If your sample is missing optional fields, those fields will not appear in the generated schema at all. If a field that is normally a string happens to be null in the sample, the generator will infer its type as null rather than string. Always use the most complete, representative sample available, and if possible use a sample that includes every optional field set to a real value rather than null.

Trusting the required array without reviewing it

The generator marks every field that appears in the sample as required. In practice, many fields in a real-world API are optional: they are present in some responses and absent in others. Before using the generated schema for validation, carefully review the required array and remove any fields that are conditionally present. Failing to do so will cause the validator to reject perfectly valid instances that simply omit optional fields.

Not adding format and pattern constraints for strings

The generator infers that a field is a string, but it cannot know from a single value that the string must be an email address, a UUID, a date in ISO 8601 format, or a value matching a specific pattern. After generating the schema, audit every string property and add a format keyword (using standard values such as "email", "date-time", "uri", or "uuid") or a pattern keyword with a regular expression for any string that has a known format constraint. This turns a structural schema into a genuinely useful data quality gate.

Assuming array item types are correctly inferred from one element

For arrays, the generator inspects the first element to determine the item type. If the array in your sample contains only one element, or if the first element is not representative of all possible elements (for example, if the array can contain multiple object shapes), the generated item schema may be incomplete or incorrect. Verify the items definition for every array property, and if the array can contain multiple distinct object shapes, replace the single items schema with an oneOf or anyOf block that covers all valid shapes.

Forgetting to set additionalProperties deliberately

The generated schema does not include an additionalProperties setting by default, which means the schema allows any additional properties not listed in properties. This is permissive: it will not reject records containing extra fields. If you want strict validation that rejects any unknown fields, add "additionalProperties": false to the relevant objects. If you are validating data from an external system that may include metadata fields you do not control, leave it as the default (open) to avoid false validation failures.

Not understanding the difference between integer and number

JSON Schema distinguishes strictly between "type": "integer" (whole numbers only) and "type": "number" (integers and floats). The generator will infer integer if the sample value has no decimal component and number if it does. If your field sometimes holds values like 1.5 and sometimes 1, but the sample only showed 1, the generated schema will declare it as integer and validation will fail on 1.5. Review every numeric field and change integer to number for any field that can hold non-integer values.

Last reviewed: June 7, 2026
Founder's Real-World Experience
S. Siddiqui

S. Siddiqui

Founder & Editor-in-Chief, YourToolsBase

Generating API documentation schemas in an afternoon instead of two days

A consulting client asked me to produce an OpenAPI specification for an internal REST API that had been running in production for two years with no formal documentation at all. The only way to understand what each endpoint returned was to read the controller code, which was neither my strength nor a good use of the engagement budget.

I ran real API calls against their staging environment using Postman, copied each response body, and pasted them one by one into the JSON Schema Generator on YourToolsBase. Within about three hours I had draft schemas for all eleven response types, including three with deeply nested objects containing eight to twelve levels of nesting. The generator handled all the recursion correctly, and I only needed to manually adjust the required arrays and add format constraints for UUID and date-time fields.

The resulting schemas went straight into the OpenAPI YAML. The client's Swagger UI documentation was live by end of day. What I estimated as a two-day task finished in one afternoon, and the schemas were accurate because they were derived from real responses rather than reconstructed from memory.

Schemas for 11 API endpoints in under 3 hours2-day task completed in 1 afternoonZero structural errors found in review
Also used alongside: JSON Schema Validator

Frequently Asked Questions

What is a JSON Schema Generator and what does it do?
A JSON Schema Generator is a tool that analyses a sample JSON document and automatically produces a JSON Schema definition describing its structure. It infers the type of every property (string, number, integer, boolean, null, object, or array), identifies nested objects, handles arrays, and produces a valid schema you can immediately use for validation, API documentation, or data contract management. It eliminates the need to write the initial schema by hand, which is tedious and error-prone for any document with more than a few fields.
How does a JSON Schema Generator work?
The generator recursively traverses your JSON sample and maps each value to its JSON Schema type. For objects, it generates a `properties` block with one entry per key and marks all present keys as required. For arrays, it inspects the first element to determine the `items` type. For primitive values it uses `typeof` logic to assign `string`, `number`, `integer`, `boolean`, or `null`. The output is a complete, syntactically valid JSON Schema document you can copy, edit, and use directly.
What is the difference between a JSON Schema Generator and a JSON Schema Validator?
A JSON Schema Generator creates a schema from sample data: you give it JSON, it produces a schema. A JSON Schema Validator checks whether a JSON document conforms to an existing schema: you give it both a schema and a JSON instance, and it tells you whether the instance passes or fails, with error details. The two tools are complementary: use the generator to create your schema from a sample, then use the validator to verify that real data conforms to that schema.
Can I generate a JSON Schema from a TypeScript interface or class?
Not directly with this tool, which generates schemas from JSON data rather than from TypeScript source code. For generating schemas from TypeScript types or interfaces, use dedicated libraries such as typescript-json-schema or zod (which can derive both runtime validation and JSON Schema from TypeScript types). For generating schemas from Java classes, use victools/jsonschema-generator. For .NET, use NJsonSchema. The approach differs by language: you need a library that understands the source type system rather than a tool that analyses JSON values.
How do I use a generated JSON Schema to validate data with JavaScript?
Use Ajv (Another JSON Validator), the most widely used JavaScript JSON Schema library. Install it with `npm install ajv`, import it, create an instance, compile your schema with `const validate = ajv.compile(generatedSchema)`, and call `validate(yourData)`. If it returns false, inspect `validate.errors` for a detailed list of violations. For schema features such as date-time format validation, also install `ajv-formats` and add it to your Ajv instance with `addFormats(ajv)`.
Which JSON Schema draft version does the generator output?
This tool generates schemas compatible with Draft-07 and above, which is the most broadly supported version across validation libraries. The output includes a `$schema` declaration so you can see which draft it targets. Draft-07 is widely supported by Ajv, jsonschema (Python), JSON.NET (.NET), and most API tools. If you need Draft 2020-12 specifically, you can change the `$schema` URI and replace `definitions` with `$defs` in the output, as these are the main structural differences between the two drafts.
Can I generate a schema from a JSON array at the top level?
Yes. If your JSON sample is an array (beginning with `[`), the generator produces a schema with `"type": "array"` at the top level and an `items` definition based on the structure of the array elements. If the array contains objects, the items definition will be a full object schema with `properties` and `required`. Paste a representative array sample that includes at least one element with all expected fields present to get the most complete items schema.
Does the generated schema handle null values correctly?
When a value in the sample is `null`, the generator infers its type as null. If the field can also hold a non-null value in real data, you need to manually update the type to allow both possibilities. In JSON Schema you can express this as an array of types: `"type": ["string", "null"]` for a field that is either a string or null. In Draft 2019-09 and 2020-12 you can also use `"oneOf": [{"type": "string"}, {"type": "null"}]`. Always check null-typed fields in the generated output and update them to reflect the full range of values the field can hold.
How do I add an enum constraint to a generated schema?
After generating the schema, find the property you want to restrict and add an `enum` keyword with an array of the allowed values. For example, to restrict a `status` field to three specific values, change its definition to `{"type": "string", "enum": ["active", "inactive", "pending"]}`. The validator will then reject any instance where `status` holds a value not in that list. Enum constraints are one of the most commonly needed additions to a generated schema, as the generator cannot infer restricted value sets from a single sample value.
What is the best way to share a generated JSON Schema with my team?
The most practical approach is to store the schema as a JSON file in your project's version control repository alongside the code that depends on it. This makes the schema reviewable in pull requests, allows it to evolve with the codebase, and gives every team member a single source of truth. For schemas used across multiple services, consider a shared schema registry or a dedicated schemas directory in a monorepo. Tools like Stoplight Studio and Swagger Editor provide visual editors for managing schemas as part of an API specification.

Rate This Tool

Was this tool helpful?

Be the first to rate this tool

About the Author

S. Siddiqui

S. Siddiqui

Founder & Editor-in-Chief

LinkedIn Profile

S. Siddiqui is the founder and editor-in-chief of YourToolsBase, overseeing all content, tool accuracy, and editorial standards.

View full profile

Authoritative Sources

Formulas and data in this tool are based on guidelines from the above sources.