How to Generate a JSON Schema from JSON (Free, In-Browser)
By Rui Barreira · Last updated: 13 June 2026
You can generate a JSON Schema from any JSON object in seconds using brevio JSON Schema Generator — paste your JSON and get a draft-07 schema instantly. All processing runs in your browser with no upload required.
JSON Schema is the standard way to define the structure of JSON data. Once you have a schema, you can validate incoming API payloads, generate TypeScript types, power form validation, and document your API contracts in OpenAPI. Writing schemas by hand is tedious and error-prone — inferring them from real examples is faster and more accurate.
What Is JSON Schema?
JSON Schema is a declarative vocabulary for annotating and validating JSON documents. The current widely-supported version is draft-07, though 2019-09 and 2020-12 also exist. Draft-07 is the safest choice for tooling compatibility — it is supported by every major JSON Schema validator (Ajv, jsonschema, fastjsonschema, etc.) and all OpenAPI 3.0 generators.
A JSON Schema document describes: the type of each field (string, number, integer, boolean, null, object, array), which fields are required, constraints on values (minLength, minimum, enum), and the structure of nested objects and arrays.
How the Inference Algorithm Works
The generator recursively inspects each value in your JSON. Primitive values map directly to JSON Schema types: a JavaScript string becomes {"type":"string"}, a JavaScript number to {"type":"integer"} or {"type":"number"} depending on whether it has a decimal component, a boolean to {"type":"boolean"}, null to {"type":"null"}.
Objects are handled by iterating all key-value pairs, generating a schema for each value, and collecting all keys into the required array. This means the generated schema assumes every key present in your example is required — a good starting point that you can relax manually for optional fields.
Arrays are handled by inspecting all elements and attempting to merge their schemas. If all elements have the same type, the items schema uses that type. If elements have mixed types, the generator uses anyOf to describe the valid types. For empty arrays, the items schema is left as an empty object {} (any type).
Required vs Optional Fields Strategy
The generator marks all object keys as required by default. In most real APIs, some fields are optional — not returned in all responses or not required in all requests. After generating the schema, review the required array and remove fields that should be optional. Fields not listed in required are allowed but not mandatory by the JSON Schema specification.
For request validation (verifying inputs to your API), you typically want a strict schema: all required fields listed, additionalProperties: false to reject undocumented keys. For response parsing (accepting API responses you don't control), you want a lenient schema: only validate the fields you care about, allow additional properties.
How to Extend the Generated Schema
Generated schemas are a starting point. Common additions after generation:
- Add
minLengthandmaxLengthto string fields (e.g., an email field:{"type":"string","format":"email","maxLength":254}) - Add
minimumandmaximumto number fields (e.g., age:{"type":"integer","minimum":0,"maximum":150}) - Add
enumfor fields with a known set of values (e.g., status:{"type":"string","enum":["active","inactive","pending"]}) - Add
formatfor typed strings (date-time, email, uri, uuid) - Add
additionalProperties: falseto reject unknown fields in strict validation contexts - Add
$defs(formerlydefinitions) to reuse repeated sub-schemas
JSON Schema Tool Comparison
| Tool | Upload? | Account? | Draft | Cost |
|---|---|---|---|---|
| brevio JSON Schema Generator | No — in-browser | No | draft-07 | Free |
| quicktype.io | No (paste) | No (web), optional | draft-07, also TypeScript | Free (web), paid API |
| jsonschema.net | Yes — server | No (basic) | draft-07, 2020-12 | Free tier, from $9/mo |
| transform.tools | No — in-browser | No | draft-07 | Free, open source |
Frequently Asked Questions
What is the difference between JSON Schema draft-07 and 2020-12?
Draft-07 is the most widely supported version — every major validator and OpenAPI 3.0 generator supports it. JSON Schema 2020-12 adds features like $dynamicRef, improved anchors, and a cleaner vocabulary system. Use draft-07 unless you specifically need 2020-12 features and have confirmed your toolchain supports it.
How do I use the generated schema to validate JSON in JavaScript?
Install Ajv: npm install ajv. Then: const Ajv = require('ajv'); const ajv = new Ajv(); const validate = ajv.compile(schema); const valid = validate(data);. If valid is false, validate.errors contains the validation errors. Ajv is the fastest and most popular JSON Schema validator for JavaScript.
Can I use this schema in OpenAPI?
Yes. OpenAPI 3.0 uses a subset of JSON Schema draft-07 for request and response body schemas. Paste the generated schema into the content section of your OpenAPI path. Note that OpenAPI 3.0 does not support all draft-07 keywords — anyOf, oneOf, $ref, and most validation keywords are supported; some meta-schema keywords ($schema, $id) may need to be removed.
Does the generator handle nested objects?
Yes. The generator recursively processes nested objects to any depth. Each nested object gets its own type: "object" block with its own properties and required arrays. The output is a single flat JSON Schema document with inline sub-schemas, not a $ref-based document. If you want to extract repeated sub-schemas into $defs, you will need to do that manually.
Frequently Asked Questions
- What is the difference between JSON Schema draft-07 and 2020-12?
- Draft-07 is the most widely supported version — supported by every major validator and OpenAPI 3.0. JSON Schema 2020-12 adds features like $dynamicRef. Use draft-07 unless you specifically need 2020-12 features and your toolchain supports it.
- How do I use the generated schema to validate JSON in JavaScript?
- Install Ajv (npm install ajv), then: const validate = new Ajv().compile(schema); const valid = validate(data). If valid is false, validate.errors contains the validation errors.
- Can I use this schema in OpenAPI?
- Yes. OpenAPI 3.0 uses a subset of JSON Schema draft-07. Paste the generated schema into the content section of your OpenAPI path. Remove $schema and $id keywords if needed for OpenAPI compatibility.
- Does the generator handle nested objects?
- Yes. The generator recursively processes nested objects to any depth. Each nested object gets its own type: "object" block with properties and required arrays inline.