JSON Schema Generator

Generate JSON Schema from JSON data automatically

JSON Input

Generated Schema

Paste your JSON on the left and the result shows up here.

Or drop a file on this box, , or .

What is JSON Schema Generator?

Ever needed to document your API's data structure but didn't want to write a JSON Schema by hand? Paste a sample of your JSON (JavaScript Object Notation) and you get a Draft-07 schema describing its structure: the type of every field (string, integer, number, boolean, null, object, array), nested objects, and which keys are required.

The schema describes the shape of your data, not the exact values. It won't copy "qty": 2 into minimum: 2, maximum: 2, because a schema that only accepts the one document you pasted is no use for validation. For arrays, every element is looked at and merged: if the second line item has a note the first one doesn't, note is in the schema but not required. Integers get "integer", decimals get "number". The output follows the official JSON Schema specification, so it loads in standard validators like Ajv.

It all runs in your browser, so your data never leaves your computer. One sample can only tell the generator so much, though: treat the result as a first draft and add formats, enums and ranges you know about.

How to Use the JSON Schema Generator

Give it a representative sample, read the schema it infers, then tighten that draft by hand before anyone validates real traffic against it.

1

Paste JSON or Upload File

Put your data in the left JSON Input panel, typed, pasted or read from disk via Upload. The Sample button gives you a subscriber record with a nested account, a devices array and a list of add-ons. Two readings from one sensor feed teach the generator more than a single record, because it merges them:

[{"sensorId": "TMP-07", "celsius": 21.4, "battery": 88}, {"sensorId": "TMP-12", "celsius": 19, "battery": 91, "note": "door open"}]

Works with objects, arrays and plain values. The more representative your sample (several array items, optional fields present in some), the better the schema. Invalid JSON shows an error.

2

View Generated Schema

The right Generated Schema panel updates as you type. It detects types (string, integer, number, boolean, null, object, array), describes nested structures, merges all array items into one item schema, and marks a key required only when every object it was seen in has it. Both panels use syntax highlighting, and the output panel is editable.

3

Copy or Download

Read the draft before you ship it. For the two sensor readings above, celsius comes out as number (one reading had a decimal), battery as integer, and note is described but left out of required. Edit what you know better, then Copy it or Download it as schema.json for Swagger/OpenAPI docs or a validator.

When You'd Actually Use This

API Documentation

Got an API response example? Generate a schema from it and use it in your Swagger/OpenAPI docs. Way faster than writing schemas by hand.

Data Validation

Need to validate incoming JSON? Generate a schema from a few real payloads, tighten it where you know more than the sample does (enums, string formats, ranges), and plug it into your validation library.

Type Definitions

Generate schemas to understand data structures. Perfect for documenting complex JSON formats or understanding API contracts.

Contract Testing

Create a baseline schema for contract tests. Because it describes types and required keys rather than exact values, a response with different data but the same shape still passes, and a missing or retyped field fails.

Common Questions

Is my JSON data stored?

No. Type inference is a short recursive function running in this tab, and the page has no save or share button for what you paste, so the sample is never sent anywhere.

What JSON Schema version is used?

We generate schemas that work with JSON Schema Draft 7 and newer. Everything follows the official spec, so it'll work with standard validation tools. Heading into an API spec? Version 3.1 of the OpenAPI Specification builds its schema objects on JSON Schema 2020-12, and a Draft-07 schema like this one usually drops in with little or no editing.

Does it handle arrays?

Yes. Every element of an array is inspected and their schemas are merged into one items schema. Objects with different keys are combined (keys missing from some items become optional), and mixed types become a type list like ["integer", "string"]. An empty array gets items: {}, since there's nothing to infer from.

What about optional vs required fields?

Within an array of objects, a key is required only if every object has it; keys that show up in some items are listed but optional. For a single object, every key in your sample is marked required, because one example can't tell the generator what's optional. Remove keys from required by hand where you know better.

Can I edit the generated schema?

Yes. The output panel is editable, so you can tweak types, add constraints like format or enum, and then copy or download your edited version. Changing the input regenerates the schema and replaces your edits, so finish with the input first.

Does it work with invalid JSON?

No. There is nothing to describe until the sample parses, so a broken one turns the right panel into a single Error: line carrying the parser's message and character position. The JSON Validator shows which line that is, and the JSON Fixer handles trailing commas and single quotes.

Other JSON Tools You Might Need

Schema generation is just one thing you might need. Here are some other tools that work great together: