JSON Schema Generator
Generate a JSON Schema from any JSON sample. Detects types, required fields, array items and string formats, for draft-07, 2019-09 and 2020-12. Free online tool.
Generate a JSON Schema from a sample
A JSON Schema describes what valid data looks like: which fields exist, what type each has and which are required. Writing one by hand is slow, especially for deep API responses. Paste a realistic JSON sample here and the generator infers a starting schema that you can then refine.
Use the result to validate API requests with a library such as Ajv, document an endpoint in OpenAPI, generate types, or add checks to a test suite.
What the generator detects
- Types for every value, including integers as distinct from other numbers.
- Array item schemas, merged across all items. If
couponappears in only some objects, it is left out ofrequired. - String formats:
date-time,date,email,uuid,uriandipv4. - Fields whose type varies across items are listed with more than one type.
Example
A single object and the schema it produces with the default options, shortened to the interesting parts.
{ "email": "asha@example.com", "age": 31 }
{
"$schema": "http://json-schema.org/draft-07/schema#",
"type": "object",
"properties": {
"email": { "type": "string", "format": "email" },
"age": { "type": "integer" }
},
"required": ["email", "age"]
}Refine the schema before you rely on it
A generator only knows the sample you gave it. If every record in your sample happens to include phone, the schema will call it required, even if the real API sometimes leaves it out. Feed in an array of varied records to get a more accurate result, then review the output by hand.
Rules that cannot be inferred from values, such as minimum, maxLength, pattern or enum, are yours to add. Turn on No additional properties when you want validation to reject unknown fields. This is useful for request bodies, though usually too strict for responses from APIs that may add fields later.
Frequently Asked Questions
Which draft should I choose?
Draft-07 has the widest library support and is a safe default. Choose 2020-12 if your tooling needs it, for example OpenAPI 3.1.
Why is a field marked as required when it is optional?
Your sample always included it. Add records without that field to your sample, or remove it from the required list by hand.
Can it detect enums?
No. A sample cannot show whether a value comes from a fixed list, so add enum yourself where it applies.
Does a valid schema mean my data is correct?
It means the data has the right shape and types. Business rules, such as a price being positive, need extra keywords or separate checks.