JSON to JSON Schema

Instantly convert JSON to JSON Schema draft-07. Infer types, required fields, arrays, and nested objects from sample JSON. Free, browser-based, no sign-up.

  • Runs in your browser
  • Your data never leaves your browser
  • Free · No Sign-Up
Clear the input, generated schema and error message. Ctrl/⌘+L within the tool also clears them and returns focus to JSON Input.
Edit the sample JSON or enter your own. Every input change immediately generates draft-07 JSON Schema. Arrays merge all their elements; required keys come from non-null values present in every sampled object.
JSON Schema (draft-07)
Copy the complete generated schema. The output is read-only; paste it into an editor to refine constraints or required fields. Empty output is not copied.

Enter JSON to generate a draft-07 schema.

Examples, details and FAQ Worked examples, how it compares with other tools, and answers to common questions.

JSON to JSON Schema Online

JSON Schema is a vocabulary that describes the structure of JSON data: expected types, required fields, format rules and the shape of nested objects. Validators such as Ajv check data against it, and it is used for API validation, code generation and documentation.

Paste a representative JSON object or array and ZeroTool will infer a draft-07 JSON Schema with object properties, required fields, array item types, and nested structures. This is a fast starting point for API validation, documentation, mocks, contract tests, and data pipeline checks.

If you searched for to_json_schema or jinja2schema infer, note the difference: template inference tools inspect Jinja templates, while this generator infers a schema from concrete JSON examples.

Understanding the Output

The generated schema always includes $schema pointing to draft-07. Object properties are inferred from the JSON keys. The required array lists every non-null key found. Array items use an inferred schema based on the elements present.

Next Steps After Generation

A generated schema is a starting point. Common refinements include: adding description fields for documentation, tightening string constraints with minLength or pattern, marking optional properties by removing them from required, and adding enum for fields with a known set of values.

Example

Input:

{
  "orderId": 1001,
  "total": 59.9,
  "coupon": null,
  "items": [{ "sku": "A1", "qty": 2 }],
  "tags": []
}

Output:

{
  "$schema": "http://json-schema.org/draft-07/schema#",
  "type": "object",
  "properties": {
    "orderId": { "type": "integer" },
    "total": { "type": "number" },
    "coupon": { "type": "null" },
    "items": {
      "type": "array",
      "items": {
        "type": "object",
        "properties": {
          "sku": { "type": "string" },
          "qty": { "type": "integer" }
        },
        "required": ["sku", "qty"]
      }
    },
    "tags": { "type": "array", "items": {} }
  },
  "required": ["orderId", "total", "items", "tags"]
}
  • A whole number becomes integer and a decimal becomes number. If qty can be 1.5, change it to number.
  • coupon is null in the sample, so its type is null and it is not in required. If it can also be a string, change the type to ["string", "null"].
  • An empty array gives "items": {}, which accepts any item.

Example: Success and Error Responses

An API that returns {"ok": true, "data": …} on success and {"ok": false, "error": …} on failure needs both shapes in the sample. Put one of each in an array:

[{"ok": true, "data": {"id": 7}}, {"ok": false, "error": "not found"}]
{
  "$schema": "http://json-schema.org/draft-07/schema#",
  "type": "array",
  "items": {
    "type": "object",
    "properties": {
      "ok": { "type": "boolean" },
      "data": { "type": "object", "properties": { "id": { "type": "integer" } }, "required": ["id"] },
      "error": { "type": "string" }
    },
    "required": ["ok"]
  }
}

ok appears in both responses, so it is the only required key; data and error are optional. Use the items schema to validate a single response. A sample with only the success response would make data required and reject every error response.

Using the Schema with Ajv

Ajv 8 validates draft-07 with its default Ajv class. The format keyword needs the ajv-formats package; without it, compile() throws unknown format "email":

import Ajv from 'ajv';
import addFormats from 'ajv-formats';

const ajv = new Ajv();
addFormats(ajv);

const validate = ajv.compile({
  type: 'object',
  properties: {
    email: { type: 'string', format: 'email' },
    coupon: { type: ['string', 'null'] },
  },
  required: ['email'],
  additionalProperties: false,
});

validate({ email: 'a@example.com', extra: 1 }); // false: must NOT have additional properties

The generator does not add format, minimum, maxLength, pattern, enum, or additionalProperties: false. Add them for the rules your data must follow.

Limits

  • Array items are merged. For [{"id": 1, "name": "Alice"}, {"id": 2, "email": "b@example.com"}], items lists id, name, and email, and only id, which every item has, is required. Integers and decimals in one array become "number". The schema always accepts the sample it came from; GenSON merges samples the same way.
  • Required comes from the sample. In a single object every non-null key is required. If a field is optional in your data but present in the sample, remove it from required yourself.
  • Mixed types give a type list. An array such as [1, "x", {"a": 1}] gives "type": ["integer", "string", "object"] with the object’s properties and required next to it. Those keywords apply only to the object items.
  • Draft-07 only. To use draft 2020-12, change $schema and use Ajv’s Ajv2020 class.

FAQ

Which JSON Schema version does this tool generate?

This tool generates JSON Schema draft-07, one of the most widely supported versions, compatible with validators like AJV, jsonschema (Python), and the JSON Schema Validator tool on ZeroTool.

How are required fields determined?

Every non-null property found in the input JSON object is added to the required array. Null values are excluded because their presence cannot be guaranteed. In an array of objects, a key is required only when every object has it with a non-null value. You can edit the output schema to adjust the required list for your use case.

Does it handle nested objects and arrays?

Yes. The tool recursively processes nested objects and arrays. Arrays get one items schema merged from all their elements, so every element passes it. Nested objects produce nested properties and required arrays.

Can I use the generated schema for validation?

Yes. Paste the generated schema into the JSON Schema Validator tool on ZeroTool or any AJV-based validator. You may need to refine optional fields or add additional constraints like minLength, minimum, or pattern.

Is my JSON sent to a server?

No. The schema is generated in your browser tab as you type, and the JSON is not sent to a server or saved in browser storage. When you finish editing the input or copy the schema, the page's analytics records one usage event with the tool name and the action (convert or copy), not the JSON or the schema.

Can this replace jinja2schema infer().to_json_schema()?

Use jinja2schema when you need to infer data requirements from Jinja templates in Python code. Use ZeroTool when you have example JSON and want to infer a draft-07 JSON Schema quickly in the browser, without installing a package.