How to convert JSON to JSON Schema
- Paste a JSON object or array, for example a response from the API you are calling.
- Set the name of the root type.
- Copy the generated JSON Schema code into your project.
What you get
- A draft 2020-12 schema with
type,propertiesandrequired. - Nested objects are defined once in
$defsand referenced with$ref. - Integers are typed as
integer, and mixed values become a list of types.
Tips for accurate results
The generator only knows the sample you paste. Include arrays with several items and responses where optional fields are present, so it can tell which keys are always there, which can be null and which numbers have decimals.
Frequently asked questions
Is my JSON sent to a server?
No. The code is generated in your browser, so API responses and other private data never leave your device.
What is JSON Schema used for?
It describes the shape of JSON documents. It is used to validate API requests and responses, document APIs in OpenAPI, power editor autocompletion for config files and generate forms.
Which fields are marked as required?
Every key present in all samples is required. When an array contains several objects, keys that appear in only some of them are left out of required.
Can I validate data with the generated schema?
Yes. Any validator that supports draft 2020-12 works, for example Ajv in JavaScript or jsonschema in Python. Review the schema first: a sample only shows the values it contains.