Data Tools
JSON Schema Generator from Sample JSON
Generate a JSON Schema from example JSON: infers types, required keys, integer vs number and formats such as email and date-time, for Draft 2020-12 to Draft-04.
How to use JSON Schema Generator from Sample JSON
Paste one JSON document, or several samples one per line, and the schema updates as you type. Choose the draft, decide how strict it should be with the tick boxes, then press Copy result.
- Paste sample JSONPaste a typical document into Sample JSON, or several compact samples one per line to merge them.
- Choose draft and optionsPick Draft 2020-12, 2019-09, Draft-07 or Draft-04 and tick required keys, integers, formats or no extra keys.
- Review and copy the schemaCheck the property count in the note, add enum or minimum rules by hand if needed, and press Copy result.
How types are inferred: a worked example
In the sample record, id: 1024 becomes "type": "integer", score: 98.5 becomes number, the email address gets "format": "email", createdAt gets "format": "date-time" and the null postcode becomes type null. The orders array holds two objects, {"id":"A-1","total":25} and {"id":"A-2","total":12.4,"coupon":"SPRING"}. Their schemas are merged into one items schema: total is a whole number in one item and a decimal in the other, so it becomes number, and coupon appears in only one item, so it is left out of required. Besides email and date-time, strings are checked for date, uuid, ipv4 and uri formats.
Several samples, required keys and strictness
Put one compact JSON document on each line to infer from several samples at once. A key is listed in required only if every sample has it, and a field that changes type between samples gets a type array such as ["string", "null"]. Empty arrays produce just "type": "array" with no items schema. Ticking Disallow extra keys adds "additionalProperties": false to every object, so validators reject unknown keys. The $schema line points at the draft you choose, which validators read to decide which rules apply. The schema only reflects your samples, so add enum, minimum, maxLength or pattern constraints yourself.
Accuracy and data handling
Keep the original data and spot-check fields, types and delimiters before using an important conversion. The calculation runs in your current browser; the tool code does not send the input to a processing API.
FAQ
What is a JSON Schema used for?
A JSON Schema describes the structure and types that JSON data must follow. It is used to validate API requests and responses, check configuration files, generate forms and documentation, and test data.
Which JSON Schema drafts are supported?
You can output Draft 2020-12, Draft 2019-09, Draft-07 or Draft-04. Only the $schema URL changes between them; the inferred type, properties, items, required and format keywords are the same.
Why is a field not marked as required?
A key is required only when it appears in every sample and in every object of an array. Keys missing anywhere are treated as optional. Untick Mark keys present in every sample as required to leave required out entirely.
More Data Tools
Related toolsValidate, pretty-print or compact JSONL and convert it to or from a JSON array.
Convert XML to JSON with attributes and repeated elements, or JSON back to XML.
Turn CSV into a GitHub Markdown table, or a Markdown table back into CSV.
Convert tab-separated spreadsheet data to CSV, or CSV back to TSV.
Switch CSV delimiters between comma, semicolon, tab and pipe, with decimal options.
Sort JSON keys alphabetically at every level, with optional array sorting.