JSON Schema generator

Runs in your browser; nothing is uploaded

Paste a JSON sample and get a JSON Schema (draft 2020-12) for it. Every item in an array is read, so required, optional and nullable properties are worked out, and dates, emails, URLs and UUIDs get their format. Nothing is sent.

JSON

Schema

Nothing yet

Paste JSON on the left, or pick an example. The schema updates as you type.
Ready
Ln 1, Col 1

From a JSON sample to a JSON Schema

A JSON Schema describes what valid JSON looks like: which properties an object has, which are required, what type each value is, and what it may contain. APIs use it to validate requests and responses, OpenAPI uses it for every body, and editors use it for autocomplete in config files.

Writing one by hand from an example is tedious. This generator reads the whole sample: when an array holds several objects, a property found in all of them is required, one missing from some is optional, and one that is null in any becomes nullable (type: ["string", "null"]). Strings that are all dates, emails, URLs or UUIDs get a format.

The schema is a starting point. Add what a sample can't show: allowed values with enum, lengths and ranges, and patterns. Strict adds additionalProperties: false, so any property not in the sample is rejected.

How to use this tool

  1. 1Paste a JSON sample, ideally with several items in its arrays and with the optional fields both present and missing.
  2. 2Choose Strict to reject unknown properties, and Formats to detect dates, emails, URLs and UUIDs.
  3. 3Copy or download the schema, then tighten it by hand where you know more than the sample shows.
  4. 4Check other documents against it with the JSON Schema validator.

Troubleshooting

A property I always send is optional
It was missing from at least one object in an array of the sample.
A property has an empty schema {}
Its values had different types in the sample, so any value is allowed. Write its type by hand.

Frequently asked questions

Is my JSON uploaded?

No. Schemas are generated and checked in your browser.

Which drafts are supported?

Draft 4, 6, 7, 2019-09 and 2020-12, including $ref, $defs and definitions, allOf, anyOf, oneOf, not and if/then/else. A $ref to another file isn't fetched; it's reported so you know that part wasn't checked.

Can I check API responses against a schema on every run?

Yes: API tests on testingapis.com check each response against its schema and alert you when one stops matching.