Skip to content

Menu

JSON Schema Generator

Generate JSON Schema (draft-07) from sample JSON data automatically.

Runs entirely in your browserJSON ToolsFree, no sign-up
Loading tool

01What is JSON Schema Generator?

Writing a JSON Schema by hand for a big API response is slow and easy to get wrong. This tool reads a sample document and writes the schema for you. Paste JSON into the JSON Input box and the schema appears next to it as you type. The output declares JSON Schema draft 2020-12 through its $schema URL, https://json-schema.org/draft/2020-12/schema. That is the dialect OpenAPI 3.1 uses. Each value gets a type: string, boolean, null, integer for whole numbers and number for anything with a fraction. Objects get a properties entry for every key. Every key in the sample goes into required, sorted alphabetically, and that includes keys whose value is null. Each object also gets additionalProperties: false, so a validator will reject keys the sample didn't have. That is strict on purpose. A sample can't tell us what is optional, so the tool assumes nothing is. Arrays are where it gets more interesting. The tool merges the schemas of all elements into one items schema. With an array of records, a key that appears in only some records stays in properties but drops out of required. Mixing 9.99 and 10 gives type number, not two competing types. Nested arrays such as [[1,2],[3.5]] merge level by level. Elements of really different kinds, like a string, an integer and an object in one list, become an anyOf with one branch each. An empty array gets items: {}, which allows anything. Here is a short case. The sample {"id":1,"name":"Ada","email":null} gives an object schema with id as integer, name as string and email as null. All three keys are required, listed as email, id, name. There are things a sample just can't show. The tool adds no format hints like email or date-time, no enum lists, and no length, range or pattern limits. There is also no draft selector. Treat the result as a first draft and tighten it by hand. Parsing and inference happen in your browser tab, and Copy or Download (schema.json) are the only ways the schema leaves it.

Backend and API developers who have example JSON in hand and want a draft 2020-12 schema to edit instead of writing one from scratch. The tool runs entirely in your browser, so your data never leaves your device.

02How to use JSON Schema Generator

  1. Paste a sample into the JSON Input box, or load the User Object, Product Array or Config example.
  2. Read the schema in the output panel. It updates as you type, and invalid JSON shows the parser error.
  3. Remove keys from required that are optional in real data, and drop additionalProperties: false if extra keys are fine.
  4. Add rules the sample can't show, such as format, enum, minLength or pattern.
  5. Press Copy, or Download to save schema.json. Reset clears the input.

03Worked examples

Input: {"id":1,"name":"Ada","email":null}
Result: { "$schema": "https://json-schema.org/draft/2020-12/schema", "type": "object", "properties": { "id": { "type": "integer" }, "name": { "type": "string" }, "email": { "type": "null" } }, "additionalProperties": false, "required": ["email", "id", "name"] }
Whole numbers become integer and required is sorted. Output reformatted onto fewer lines.
Input: [{"price":9.99},{"price":10}]
Result: "items": { "type": "object", "properties": { "price": { "type": "number" } }, "additionalProperties": false, "required": ["price"] }
9.99 and 10 merge to number. Trimmed to the items part.
Input: {"tags":["a",1,{"k":true}]}
Result: "tags": { "type": "array", "items": { "anyOf": [ { "type": "string" }, { "type": "integer" }, { "type": "object", "properties": { "k": { "type": "boolean" } }, "additionalProperties": false, "required": ["k"] } ] } }
Different kinds of element become anyOf. Trimmed to the tags property.
Input: {"grid":[[1,2],[3.5]]}
Result: "grid": { "type": "array", "items": { "type": "array", "items": { "type": "number" } } }
Nested arrays merge at each level. Trimmed to the grid property.
Input: {"items":[]}
Result: "items": { "type": "array", "items": {} }
An empty array gives an empty items schema, which accepts anything.
Input: {bad
Result: Expected property name or '}' in JSON at position 1 (line 1 column 2)
Invalid input shows the browser's JSON parser message. Wording can differ between browsers.

04Common use cases

  • Turning a captured API response into a starting schema for request validation middleware such as Ajv
  • Drafting component schemas for an OpenAPI 3.1 file from example payloads a partner sent you
  • Pasting an array of real records to find out which fields are actually optional across them
  • Documenting the message format between two services from a few logged queue messages
  • Building a schema for a project config file so editors like VS Code can flag mistakes
  • Checking how mixed arrays in legacy data would need to be described before a migration

05Tips

  • Paste an array of several real records instead of one. Keys missing from any record leave required automatically.
  • A field that is null in your sample becomes type null only. Change it to ["string", "null"] if it is usually a string.
  • OpenAPI 3.0 uses an older schema dialect without type null, so edit nullable fields before pasting there.
  • If anyOf shows up in items, check whether the mix of types in that array is intended or a data bug.
  • Check the $schema line before pasting into a tool that expects an older draft. The output is always 2020-12.

06Related concepts

JSON Schema 2020-12, OpenAPI 3.1, Ajv validator, Schema inference.

Frequently Asked Questions

What is JSON Schema Generator?

JSON Schema Generator is a free, browser-based developer tool on AIDToolStack. Generate JSON Schema (draft-07) from sample JSON data automatically. It requires no installation or sign-up and works entirely in your browser.

Is JSON Schema Generator free to use?

Yes. No sign-up, no fees and no usage cap.

Does JSON Schema Generator store my data?

No. It runs in your browser; nothing is uploaded.

Cheat sheet

Related Tools

Reviews and commentsShow

Reviews

Sign in to leave a review.

Loading reviews…

Comments

Sign in to leave a comment.

Loading comments…

What changed in AI dev tools, once a month

Renames, shutdowns, pricing changes and new MCP setups, each with a source.

Subscribe