Schema Generation

JSON Schema Generator: Document Your API Contracts Without Writing Schemas by Hand

You have a JSON response from your API. It works. Your consumers are happy. Then someone asks for the schema — "What fields does the orders endpoint return? Which ones are required? What types are those fields? Can the status field be null?" You open the response in a text editor and start counting: ten fields at the top level, three are nested objects, two are arrays of objects, some fields only appear in certain response variants. By the time you have manually transcribed the structure, a new version of the API has shipped and your schema is already stale.

This tool generates a JSON Schema document from any JSON object or array. Paste your data, and it infers the structure, types, required fields, and constraints automatically — producing a Draft-07 compatible JSON Schema that you can use for API documentation, client-side validation, automated contract testing, or OpenAPI specification generation. No manual transcription, no type-by-type annotation, no risk of schema drift from the actual data.

How It Works

Paste any valid JSON into the input panel — a single object, an array of objects, a deeply nested structure with mixed types — and click Generate Schema. The generator walks the entire structure and produces a JSON Schema document that captures the observed structure with correctly inferred types and constraints.

The schema inference is more nuanced than a simple type mapping. For each field, the generator examines every occurrence across all objects in the data and selects the narrowest correct type that covers all observed values. A field that is always an integer becomes {"type": "integer"}. A field that holds integers in some objects and null in others becomes {"type": ["integer", "null"]}, correctly reflecting the nullable semantics rather than forcing a single type that would fail validation. Required fields are identified by checking which keys appear in every single object across the dataset.

For arrays, the generator inspects the element types inside the array. An array of strings becomes {"type": "array", "items": {"type": "string"}}. An array of objects triggers deeper schema generation on those objects. Empty arrays get {"type": "array"} with no items constraint, since there is no data to infer element types from.

Nested objects are fully expanded. A field like {"address": {"street": "123 Main", "city": "NYC", "zip": "10001"}} produces a nested JSON Schema object with individual property definitions for street, city, and zip, each with their own inferred types and descriptions. This nesting recurses to any depth, so a response hierarchy of five or six levels is fully captured in the schema.

The generated schema follows JSON Schema Draft-07 conventions and is compatible with all major validators: ajv for JavaScript and Node.js, jsonschema for Python, the OpenAPI 3.0 specification ecosystem, and any editor that provides JSON Schema-based autocompletion like VS Code, IntelliJ, and Sublime Text.

The output schema includes $schema and title fields at the root level, making it self-documenting and immediately usable as a standalone schema file. You can save it as response-schema.json, commit it to your repository alongside your API code, and reference it from OpenAPI $ref pointers without any post-processing. If your input JSON is an array, the generator wraps the schema in an array type and infers the item schema from the array elements — the same logic whether you paste one object or a thousand.

Real-World Scenarios

API documentation. A backend developer is writing documentation for a new REST endpoint. Instead of manually listing every response field with its type and description — a process that is error-prone and goes stale the moment the code changes — they paste a real API response into the schema generator, copy the resulting JSON Schema into the OpenAPI specification file, and the documentation always matches what the endpoint actually returns.

Client-side validation. A frontend developer receives JSON data from a third-party API and needs to validate responses before rendering them in the UI. They paste a sample response, generate the schema, and wire it into their application's validation layer using ajv. Invalid responses are caught at the boundary rather than causing cryptic rendering errors deep in the component tree.

Contract testing. A QA engineer sets up contract tests between a frontend application and a backend service. They generate schemas from known-good API responses, then configure the CI pipeline to validate every new response against the stored schema. When the backend team accidentally changes a field type or removes a required field, the contract test catches it immediately instead of the frontend silently breaking in production hours later.

What the Generator Cannot Infer

The schema generator operates on observed data, not on declared intent. A field that happens to be the integer 42 in your sample data might conceptually allow any positive integer, but the schema only knows that it observed 42. If you need format constraints — email addresses, URI patterns, date-time strings — add them manually to the generated schema after generation. The tool provides the structural and type-level foundation; semantic constraints are your domain expertise applied as a refinement pass.

Fields that are absent from the sample data do not appear in the generated schema. If your response has an optional field that only appears in 5% of requests but your sample data happened to not include that case, the schema will not document that field. Generate schemas from representative data that exercises all code paths and response variants, or combine schemas generated from multiple sample responses to cover the full API surface.

For best results, provide a diverse sample that includes edge cases: objects with null fields, arrays with mixed element types if your API permits them, and at least a few objects that differ slightly in their key sets to expose which fields are truly required versus conditionally present. The richer your sample data, the more accurate and useful the generated schema.

Privacy

JSON parsing, recursive tree walking, type inference, and schema generation all execute entirely in your browser using JavaScript. Your API responses — which may contain customer data, internal business logic exposed through field names and structures, or proprietary data models — never leave your device. This is particularly important when generating schemas from production data samples that contain real customer information.

JSON Schema Generator FAQ

Which JSON Schema draft does this tool produce?

Generated schemas follow Draft-07 conventions and work with validators like Ajv, Python jsonschema, and OpenAPI 3.0 tooling.

Can I use an array of objects as input?

Yes. The generator inspects array items and builds an items schema from the observed element structure.

Does the tool add format constraints like email or date-time?

No. It infers structural types from sample data only. Add format keywords manually after generation when you know the semantic intent.