toolqik

71 · JSON

JSON Schema Generator

Infer a JSON Schema from example JSON, with formats, required fields and nullables.

Runs in your browser
Draft
Required
Options

JSON Schema

  

About this tool

Writing a JSON Schema by hand is slow and error-prone. Paste an example of your JSON and this generator infers a schema: the type of every field, nested objects and arrays, which fields are required, which can be null, and common string formats such as email, date-time, uri and uuid. Use it to validate API requests, document payloads, or bootstrap an OpenAPI spec.

Better schemas from several examples

One example can’t show which fields are optional. Turn on Top-level array = several examples and paste an array of objects: fields missing from any example become optional, values that are sometimes null become nullable, and integer and decimal numbers merge into number.

After generating

  • Add constraints the data can’t reveal: minLength, maximum, enum, pattern and descriptions.
  • Validate with Ajv (JavaScript), jsonschema (Python) or your framework’s validator.
  • No extra properties adds additionalProperties: false, which catches typos in field names but rejects new fields until you update the schema.
// npm install ajv ajv-formats
import Ajv2020 from 'ajv/dist/2020.js';
import addFormats from 'ajv-formats';

const ajv = new Ajv2020();
addFormats(ajv);
const validate = ajv.compile(schema);
if (!validate(data)) console.log(validate.errors);

FAQ

How do I generate a JSON Schema from JSON?

Paste example JSON above. The schema is generated instantly; copy it or download schema.json.

Which JSON Schema version should I use?

Draft 2020-12 is the current version and is used by OpenAPI 3.1. Choose draft-07 for older validators.

How are optional fields detected?

With several examples, fields that are missing from any example aren’t required. With one example, choose whether all present fields are required.

Does it detect formats like email and dates?

Yes: email, date-time, date, time, uri, uuid and ipv4, when every example value matches.

esc
↑↓ navigate↵ open