JSON to JSON Schema
Paste a sample JSON document and get a JSON Schema that describes it. Prettify infers the type of every value, lists the required properties, and adds a definition for each nested object, so you start from a working schema instead of an empty file.
What the generator infers
Prettify generates the schema with quicktype. Each value gets a type: string, number, integer, boolean, null, object, or array. A whole number becomes integer. Strings in ISO date and time format get a format such as date-time. Arrays get the schema of their items.
Each object shape becomes a definition under definitions, and the root of the schema refers to the Root definition. Every property in the sample is listed in required, because the sample is all the generator knows.
Key features
The result is a complete schema that a validator can use at once.
- A $schema line that declares draft-06, with keywords that later drafts also accept.
- A definition for each object shape, so nested objects are reusable.
- additionalProperties set to false, so unknown keys fail validation.
- A required list for every object, sorted by name.
- A format for date and time strings.
- Download saves the result as prettify.schema.json.
How to generate a JSON Schema
Generate in the box on this page, or with Generate Types in the editor. The generator loads the first time you use it. The box takes samples up to 512 KB.
- Paste a JSON sample into the box labeled "Paste your JSON", or select "Try an example".
- Read the schema in the panel labeled JSON Schema.
- Select Copy, or Download to save prettify.schema.json.
- Remove the properties that are optional in your data from each required list.
- Check real documents against the schema in the JSON Schema Validator.
Worked example: a user record
The sample below is a small user record. The second block is the schema from the box.
The id became integer, and joined got the date-time format. The email is a plain string: the generator does not add the email format, so add "format": "email" by hand if you want a validator to check addresses. Because additionalProperties is false, a document with an extra key fails.
{
"id": 1042,
"email": "ada@example.com",
"joined": "2024-03-01T09:30:00Z",
"tags": ["admin"]
}
{
"$schema": "http://json-schema.org/draft-06/schema#",
"$ref": "#/definitions/Root",
"definitions": {
"Root": {
"type": "object",
"additionalProperties": false,
"properties": {
"id": {
"type": "integer"
},
"email": {
"type": "string"
},
"joined": {
"type": "string",
"format": "date-time"
},
"tags": {
"type": "array",
"items": {
"type": "string"
}
}
},
"required": [
"email",
"id",
"joined",
"tags"
],
"title": "Root"
}
}
}Edit the schema before you use it
A generated schema is a strict description of one sample. Real data varies, so plan to loosen it in a few places.
- Remove properties that may be missing from the required lists.
- Change additionalProperties to true where other keys are allowed.
- Add formats such as email and uri, and limits such as minimum and maxLength.
- Allow null where a value may be empty, with a type list such as ["string", "null"].
Validate with the schema
In the editor, attach the schema to a JSON or YAML document to see every error in the Problems panel, with its path and line. Schema validation is a Pro feature, and free users get one free try a day. Generating the schema is free.
Common uses
A schema written from a real sample saves the slowest part of the work: listing every property and its type.
- Start a schema for an API request or response.
- Describe a JSON config file so an editor can check it as you type.
- Write a contract for data that two teams exchange.
- Add a check for test fixtures, so a fixture with the wrong shape fails.
Limits to know
The generator infers types and date formats only. It does not add value rules such as minimum, maximum, maxLength, or pattern, because one sample cannot show the limits of your data. It does not detect email addresses or URLs. Add those rules by hand after you generate the schema.
Frequently asked questions
Which JSON Schema version is generated?
The output declares draft-06 and uses only keywords that later drafts also accept, so validators for draft-07 and 2020-12 read it too.
Is my sample uploaded?
No. The schema is generated in your browser. The generator loads the first time you use it and then runs on your device.
Why is every property required?
The sample has every property, so nothing in it shows that one is optional. Delete properties from the required list when your real data may leave them out.
Why does an extra key fail validation?
The generator sets additionalProperties to false on each object. Change it to true, or remove it, when documents may hold keys that the sample does not have.
Can I generate types for code too?
Yes. The JSON to TypeScript page generates interfaces, and Generate Types in the editor also writes Go, Kotlin, and Rust types from the same document.
How do I check a document against the schema?
Attach the schema to the document in the editor, and every error shows in the Problems panel with its path and line. Schema validation is a Pro feature with one free try a day.