Last updated:
JSON to JSON Schema Generator
Paste any JSON and get a JSON Schema for it. This JSON to JSON Schema generator detects types, string formats, nested objects and arrays. Then refine it with constraints, descriptions and enum values.
What this tool does
Writing a JSON Schema from a blank editor is tedious; deriving one from a real payload you already have in front of you is fast and produces fewer transcription bugs. This generator inverts the usual workflow. Paste a JSON document — an API response, an event from your analytics pipeline, a sample config file, anything that round-trips through JSON.parse — and the tool walks the value tree and emits a JSON Schema that describes the shape it observed, complete with type narrowing, format detection, and proper nesting.
The generated schema is a starting point, not a finished artifact. Schema inference can only see what is in the sample: types come from the values present, required-ness comes from presence, and constraints come from format heuristics like "this string looks like an email address." The refinement panel below the output is where the schema becomes production-ready — toggling required versus optional, adding enums, tightening number ranges, and writing descriptions. The whole pipeline is browser-local; no payload, however sensitive, is transmitted anywhere.
When to use the JSON to Schema Generator
Drafting validation for an API endpoint you own. You have a handler that already builds the response object. Capture one real response, paste it in, refine the optional fields, and you have the schema to drop into your test suite or your gateway's request validation.
Reverse-engineering a vendor's response shape. The vendor's documentation is sparse, the OpenAPI spec is missing fields you can see in the actual responses, and you need a schema for your own SDK. Paste a few sample responses, merge them, and the generator infers a schema that matches reality rather than the marketing docs.
Building a contract from production log samples. Take a representative slice of recent payloads from your event pipeline, paste them in as JSON Lines (one event per line), and let the multi-sample merge figure out which fields are universal and which are conditional. This is faster than reading the producer's source code and more accurate than reading the docs.
Bootstrapping a config-file schema. Many tools accept a config file with a sprawling shape and no schema. Paste a working config, refine the optional fields, and you have a schema to attach to "$schema" in the file so editors like VS Code can offer autocomplete and red-squiggle validation to the people writing it.
Walkthrough with a real example
Paste this analytics event payload into the generator:
{
"event_id": "evt_01HQ8X9YZ4M2NK7PQRT5V3W6BJ",
"event_type": "page_view",
"occurred_at": "2026-04-29T18:42:11.000Z",
"user": {
"id": "u_938741",
"email": "casey@example.com",
"is_signed_in": true
},
"page": {
"url": "https://schema.biz/database/designer/",
"referrer": "https://www.google.com/",
"title": "Free Visual Database Schema Designer"
},
"device": {
"platform": "macos",
"viewport": {
"width": 1440,
"height": 900
}
},
"session_seconds": 287
}
The generator's output has every nested object turned into its own object schema, formats detected for the strings that pass a format check, and integer for fields whose values are whole numbers:
{
"$schema": "https://json-schema.org/draft/2020-12/schema",
"type": "object",
"properties": {
"event_id": {
"type": "string"
},
"event_type": {
"type": "string"
},
"occurred_at": {
"type": "string",
"format": "date-time"
},
"user": {
"type": "object",
"properties": {
"id": {
"type": "string"
},
"email": {
"type": "string",
"format": "email"
},
"is_signed_in": {
"type": "boolean"
}
},
"required": [
"id",
"email",
"is_signed_in"
]
},
"page": {
"type": "object",
"properties": {
"url": {
"type": "string",
"format": "uri"
},
"referrer": {
"type": "string",
"format": "uri"
},
"title": {
"type": "string"
}
},
"required": [
"url",
"referrer",
"title"
]
},
"device": {
"type": "object",
"properties": {
"platform": {
"type": "string"
},
"viewport": {
"type": "object",
"properties": {
"width": {
"type": "integer"
},
"height": {
"type": "integer"
}
},
"required": [
"width",
"height"
]
}
},
"required": [
"platform",
"viewport"
]
},
"session_seconds": {
"type": "integer"
}
},
"required": [
"event_id",
"event_type",
"occurred_at",
"user",
"page",
"device",
"session_seconds"
]
}
Walk through what the generator inferred. occurred_at is a valid date-time with a time zone, so it gets format: date-time; email passes the email check; both URL fields get format: uri. session_seconds is a whole number in the sample, so it is narrowed from number to integer. The viewport object becomes a fully typed nested schema with its own required array. Every property in the sample is marked required by default — a strict starting point that you almost always want to relax in the refinement panel.
The refinement step is where the schema earns its keep. The generator cannot tell that event_type is one of a known set of values, but you can: type them into its row's enum box in the Refine Schema table. Same with event_id: the part after evt_ is a ULID, which isn't a built-in format, but its row takes a regex pattern. session_seconds deserves a sane upper bound so a buggy producer that emits a million-second session gets caught at the gateway, and since a direct visit has no referrer, untick Required on page.referrer, a nested row like any other:
// After refinement: a pattern on event_id, an enum on event_type, bounds on session_seconds
{
"event_id": {
"type": "string",
"pattern": "^evt_[0-9A-Z]{26}$"
},
"event_type": {
"type": "string",
"enum": [
"page_view",
"click",
"form_submit",
"purchase"
]
},
"session_seconds": {
"type": "integer",
"minimum": 0,
"maximum": 86400
}
} Run the refined schema against five more sample events using the JSON Schema Validator and any property that is sometimes missing in real traffic shows up as a validation failure on the "is required" rule. Or paste all the events here as JSON Lines in the first place, and the generator marks those properties optional for you. Walk those failures back into the schema as optional, and after two or three rounds you have a schema that matches the producer's real behavior rather than just one sample's behavior.
Schema inference concepts you should know
Type narrowing from sample values. JSON has only one numeric type, but JSON Schema distinguishes integer from number. The inference rule is straightforward: if every observed value for a numeric field is a whole number with no fractional part, the field is narrowed to integer. The risk is that a field whose values happen to be whole in your sample will be typed too strictly — a price field always at $1, $2, $3 in dev gets the integer treatment until a $1.99 row breaks it.
Format detection. The generator checks every string for six formats: date, date-time, email, uri (http and https addresses), uuid and ipv4. It uses the same checks the Ajv validator does, so a string that almost matches, such as 2024-02-30 or 999.1.1.1, stays a plain string, and the schema never rejects its own example. When the strings of one property have different formats, the format is left out. For a domain-specific shape the generator doesn't know, add a regex pattern in the Refine Schema table.
Required by presence. Every property in a sample is marked required, on the principle that the safest default is the strictest one. This is often wrong, since many sampled payloads happen to include optional properties, so every row in the Refine Schema table, nested ones included, has a Required checkbox. Multi-sample inference does this automatically: a property missing from any sample is optional in the merged schema.
Array inference and union types. If every element of an array has the same type, the array's items schema is that single type. If elements vary, whole numbers and decimals together become number, one kind plus null becomes a type list such as ["string", "null"], and anything else becomes anyOf with one branch per kind (never oneOf, which would reject a value that fits two branches). For arrays of objects, the elements are merged the same way multi-sample inference works: properties that appear in every element are required, others optional. Arrays inside arrays are merged level by level.
The reliability ceiling of one-sample inference. A single sample can tell you the shape of the value it actually contains, but cannot tell you which fields are conditional, what values an enum field accepts, what bounds are reasonable, or which formats apply to ambiguous strings. Treat one-sample output as the rough draft and use multi-sample input plus refinement to converge on a schema that matches the real range of the data.
The relationship between schema and data evolution. A schema generated today describes the data as it exists today. When the producer adds a field, your generated schema does not know about it; when the producer renames a field, your schema rejects the new payload. Treat the generator as a starting point for a schema you maintain in version control, not as a runtime inference layer that auto-adapts to producer changes.
Common mistakes
Treating one sample as the complete picture. A single event from the analytics pipeline cannot tell you which optional fields exist or what the full enum membership is. Sample at least a handful of payloads and paste them as JSON Lines.
Shipping the schema with everything still marked required. The default-required behavior is correct as a starting point and dangerous as a final state. The first edge-case payload that omits a "required" optional field will fail validation noisily. Walk the Refine Schema table and untick Required on the truly optional ones before publishing the schema.
Trusting format detection blindly. The generator labels a string with format: email if it matches the email regex. If your application's idea of an "email" is actually a username that occasionally contains an @ for legacy reasons, the format annotation is wrong. Audit each format the generator added before accepting it.
Skipping the constraint pass on numbers and strings. The inferred schema gives you types and required-ness but no minimum, maximum, minLength, maxLength, or pattern. A schema without bounds will accept negative ages, billion-character display names, and whitespace-only emails. Add the bounds the domain actually requires.
Not validating the generated schema against more samples. The fastest way to find inference mistakes is to run the schema against payloads it was not generated from. Drop the schema and ten more samples into the JSON Schema Validator; every failure is either a producer bug or a place the schema needs to be relaxed.
FAQ
How does the generator decide between 'number' and 'integer'?
If every numeric value in the sample is a whole number, the field is typed as integer; if any value has a fractional component, it is typed as number. This is a sample-driven decision, so a price field that happens to round to whole dollars in your sample will be typed as integer until a $4.99 row is included.
What happens with null values in the input?
A property whose only value in the sample is null is typed as null, which is rarely what you want: pick its real type in the Refine Schema table, or add a sample where it has a value. With several samples, a property that is a string in one and null in another becomes ["string", "null"].
Can the generator handle JSON with comments (JSONC) or trailing commas?
No. The input is read with the browser's strict JSON parser, so comments and trailing commas are syntax errors, and the error message says where. Remove them first, or convert a JSONC or YAML config to plain JSON before pasting it.
Can I generate one schema from multiple JSON samples?
Yes. Paste the samples as JSON Lines, one JSON value per line, and the generator merges them into one schema. Properties that appear in every sample are required and the others optional; a property with different types across samples gets a type list such as ["integer", "string"], or anyOf when objects or arrays are involved. The objects inside one array are merged the same way. This is the best way to describe a real API's responses.
Which JSON Schema draft does it emit by default, and can I change it?
Draft 2020-12 by default, the latest stable draft. The dropdown lets you target Draft 4, 6, 7, or 2019-09 instead, which changes the $schema URI. The rest of the schema is the same in every draft: it only uses keywords that mean the same thing in all five (type, properties, required, items, anyOf, format, and the bounds, patterns and enums you add), and the tool's tests check that each schema accepts its own example under every draft.
Related tools and guides
- JSON Schema Validator — once the generator emits a schema, validate it against more sample payloads to find places the inference was too strict or too loose. The two tools are designed to be used in a tight loop.
- Schema Format Converter — turn the generated JSON Schema into TypeScript, Zod, Pydantic, GraphQL, or Go for the consumer side of your stack.
- Mock Data Generator — generate additional sample payloads from the inferred schema so you can pressure-test it without waiting for real traffic.
- Complete Guide to JSON Schema — the full vocabulary the generator emits, including the constraints and patterns you will add during refinement.
- API Versioning Guide — when the producer changes the payload shape, the schema is part of your contract; this guide covers the patterns for evolving it without breaking consumers.