How to use the json generator from schema
- Paste your JSON Schema into the JSON Schema box. Draft-07 and 2020-12 keywords both work.
- Choose whether optional properties are included or only the required ones.
- Set a Seed. Keep it to reproduce the same sample later, or change it to get different values.
- Copy the generated JSON, then check it with your own validator before you rely on it in a test or mock.
How this JSON generator from schema builds a sample
The generator reads your schema and builds one value that satisfies it, walking from the root down. At each node it looks for const first, then enum, then the type. Numbers and strings are drawn from a seeded pseudo-random generator, so a given schema and seed always produce the same document. That makes the output safe to commit as a fixture or to paste into a bug report.
A typical run on an object with a required name string of 3 to 30 characters and an age integer from 18 to 65 returns a name inside that length and an age inside that range. If you want to generate json from schema for a quick mock API response, this is the whole workflow: paste, copy, done.
Supported schema keywords
| Keyword | What the generator does |
|---|---|
type | string, number, integer, boolean, null, object and array. For a list of types the first non-null type is used. |
enum, const | const is used as is. enum picks one listed value. |
minimum, maximum, exclusiveMinimum, exclusiveMaximum, multipleOf | Stays inside the range, respects exclusive bounds and returns a true multiple. |
minLength, maxLength, pattern | Builds text of the right length. Common patterns such as ^[A-Z]{3}-[0-9]{4}$ are sampled and re-checked. |
format | date, time, date-time, email, uri, uuid, ipv4, ipv6, hostname and a few more. |
properties, required, additionalProperties | Builds nested objects. A required name missing from properties becomes a string. |
items, prefixItems, minItems, maxItems, uniqueItems | Builds arrays, tuples and unique lists. |
allOf, oneOf, anyOf, $ref | allOf is merged, oneOf and anyOf use the first branch, and local refs to #/$defs/... or #/definitions/... are followed. |
Making a json sample from schema reproducible
Random test data is only useful if you can get it back. The seed field is a plain integer that starts the generator, so seed 1 and seed 2 give two different but repeatable documents. Use one seed for the screenshot in your docs and another for the unit test fixture.
If you need a different shape rather than different values, change the schema: raise minItems to get a longer list, or switch the object option to Required properties only to see the smallest valid document. That minimal sample is a good check that your schema does not demand more than you think.
Limits you should know about
Keywords that only restrict values are not all enforced. not, if/then/else, patternProperties, propertyNames, contains and dependentRequired are ignored, and the tool says so in a note when it meets them. References must be local, so a $ref to a URL cannot be followed.
- oneOf always takes the first branch. If that branch also matches a second branch, a strict validator will reject the value. Make the branches mutually exclusive.
- Impossible schemas such as
minimum 17, maximum 17, multipleOf 2have no valid value. The tool returns its closest guess and a note. - Recursive schemas with optional children stop growing after a few levels. A recursion made only of required members is cut off.
- Decimal multipleOf values like 0.01 can fail in validators that use floating point division. Powers of two, such as 0.5 and 0.25, are exact.
Where generated JSON is useful
Typical uses are mock API responses, seeding a local database, fixtures for contract tests, documentation examples and checking that a schema is not accidentally too loose or too strict. Teams that keep one schema as the source of truth can generate the sample for each endpoint instead of writing it by hand.
To go the other way and infer a schema from an existing document, use the JSON to JSON Schema converter. To check a document against a schema, use the JSON Schema validator. For a quick syntax check before you paste, the JSON validator helps.
Worked examples
| Example | Input | Result |
|---|---|---|
| User record with formats | JSON Schema: { / "$schema": "https://json-schema.org/draft/2020-12/schema", / "type": "object", / "required": [ / "id", / "name", / "email", / "roles" / ], / "properties": { / "id": { / "type": "string", / "format": "uuid" / }, / "name": { / "type": "string", / "minLength": 3, / "maxLength": 30 / }, / "email": { / "type": "string", / "format": "email" / }, / "age": { / "type": "integer", / "minimum": 18, / "maximum": 65 / }, / "active": { / "type": "boolean" / }, / "roles": { / "type": "array", / "items": { / "enum": [ / "admin", / "editor", / "viewer" / ] / }, / "minItems": 1, / "maxItems": 2, / "uniqueItems": true / } / } / }; Seed: 1 | { / "id": "35c8cada-6699-4840-9f55-82925aa04322", / "name": "Lena Stone", / "email": "ravi87@harbor.example.com", / "age": 40, / "active": false, / "roles": [ / "viewer", / "admin" / ] / } |
| Shared definitions with $ref | JSON Schema: { / "$defs": { / "addr": { / "type": "object", / "required": [ / "city", / "zip" / ], / "properties": { / "city": { / "type": "string" / }, / "zip": { / "type": "string", / "pattern": "^[0-9]{5}$" / } / } / } / }, / "type": "object", / "required": [ / "home", / "work" / ], / "properties": { / "home": { / "$ref": "#/$defs/addr" / }, / "work": { / "$ref": "#/$defs/addr" / } / } / }; Seed: 2 | { / "home": { / "city": "Zoe Okafor", / "zip": "30786" / }, / "work": { / "city": "lantern ember", / "zip": "13876" / } / } |
| Array of line items | JSON Schema: { / "type": "array", / "items": { / "type": "object", / "required": [ / "sku", / "qty", / "price" / ], / "properties": { / "sku": { / "type": "string", / "pattern": "^[A-Z]{2}-[0-9]{4}$" / }, / "qty": { / "type": "integer", / "minimum": 1, / "maximum": 9 / }, / "price": { / "type": "number", / "minimum": 0.5, / "maximum": 99.5, / "multipleOf": 0.5 / } / } / }, / "minItems": 3, / "maxItems": 3 / }; Seed: 3 | [ / { / "sku": "FI-6033", / "qty": 9, / "price": 2 / }, / { / "sku": "EE-9806", / "qty": 3, / "price": 25 / }, / { / "sku": "GP-4972", / "qty": 7, / "price": 29 / } / ] |
| oneOf uses the first branch | JSON Schema: { / "type": "object", / "required": [ / "payment" / ], / "properties": { / "payment": { / "oneOf": [ / { / "type": "object", / "required": [ / "card" / ], / "properties": { / "card": { / "type": "string", / "pattern": "^[0-9]{16}$" / } / } / }, / { / "type": "object", / "required": [ / "iban" / ], / "properties": { / "iban": { / "type": "string" / } / } / } / ] / } / } / }; Seed: 4 | { / "payment": { / "card": "4234968706139464" / } / } |
FAQ
Is the generated JSON always valid against my schema?
For the supported keywords it is. Impossible constraints, the ignored keywords listed above and oneOf branches that overlap can produce a value that a strict validator rejects. Notes under the result point these out.
How do I generate JSON from a schema with a $ref?
Keep the definitions in the same document under $defs or definitions and point to them with a local reference such as #/$defs/address. The tool follows the pointer and builds that part of the sample.
How does the json generator from schema choose values?
Values come from a seeded generator, so the output depends only on the schema and the seed. Change the seed number to get a different sample from the same schema.
Which JSON Schema drafts does it support?
Draft-07 and 2020-12 keywords are read, including both the items array form and prefixItems for tuples.
Can I use the result as a json sample from schema for tests?
Yes. Copy it into a fixture and keep the seed in a comment next to it, so anyone can reproduce or regenerate it.
Is my schema uploaded?
No. The sample is generated in your browser and nothing leaves the page.
Sources and references
- JSON Schema specification: the keywords the generator reads