JSON Schema Generator
Turn sample JSON into a draft-07 JSON Schema in the browser—types, nesting, arrays, enums, common string formats, and strict or loose required fields—with one-click copy.
Try it now: Open the free JSON Schema Generator tool — no sign-up required.
From sample payloads to a draft-07 schema
JSON Schema shines when it mirrors real traffic. Pasting a representative object or array gives you a starting properties map, type keywords for primitives, merged shapes for array items, and optional enum when repeated string values suggest a closed set. The generator adds $schema for draft-07 so you can drop the result into editors and validators without retyping structure by hand. When inputs are noisy, normalize with JSON Formatter first, then infer.
Strict versus loose required fields
Strict mode encodes a “everything we saw must be present” contract: each object gets a required array listing every key discovered at that level. That matches generated SDKs, internal APIs, and config files where omissions are bugs. Loose mode skips required, which suits analytics exports, user-generated records, or partial fixtures where absence is valid. Neither mode invents constraints you did not imply from the sample—you still edit the schema for minLength, pattern, or additionalProperties if your domain needs them.
Arrays, nested objects, and merged types
Arrays of objects merge keys across elements so optional columns appear in properties even when only some rows set them. Arrays of mixed primitives or nested arrays produce items schemas, and when the same logical slot holds incompatible shapes, the tool may emit anyOf to preserve fidelity. For tabular data ingested as JSON rows, CSV to JSON often produces cleaner samples than hand-built snippets. For configs that live in YAML, round-trip through JSON ⇄ YAML so you infer from the same structure your runtime parses.
String formats, JWTs, and validation in production
Detected format values (email, dates, URIs, IPs, UUIDs) reflect pattern checks on the strings you provided—they are not a substitute for full RFC validation in every stack. Token-shaped strings such as JWTs are not special-cased; use JWT Parser when you need header and claim inspection instead of schema structure. Before enforcing a generated schema in production, run it through your chosen validator against positive and negative fixtures, and extend with business rules the sample data never showed.
Frequently Asked Questions
- What JSON Schema version does this tool use?
- The output sets `$schema` to `http://json-schema.org/draft-07/schema#`. Keywords match what most draft-07 validators and editors expect; confirm against your runtime if you rely on newer drafts.
- What is the difference between Strict and Loose mode?
- Strict lists every property key the tool saw under `required` at each object level—good for configs and APIs where missing keys should fail validation. Loose omits `required`, so properties behave as optional—better for sparse or exploratory samples.
- When does the tool emit an enum for a string field?
- Inside an array of objects, when the same key appears as a string on every sampled row, the array has at least three items, and there are between one and five distinct string values, the schema uses `enum` with those values (sorted). Outside that pattern, strings stay plain `type: string`, often with `format` when a heuristic matches.
- Which string formats are detected?
- Heuristics may add `format` for uuid, email, date, date-time (ISO-style), uri (http/https), ipv4, and ipv6. How strictly those apply depends on your validator; treat them as hints and tighten rules in your own schema if needed.
- Is my JSON sent to a server?
- No. Parsing and schema generation run entirely in your browser; nothing is uploaded for this tool.
Ready to try it yourself?
Use JSON Schema Generator for Free