JSON to JSON Schema generator

A quick starting point for documenting an API or validating data; refine the constraints afterwards.

Loading the tool…

Processing and privacy: The result is calculated inside your browser and your data is not sent to any server.

How to use it

  1. Enter json input and root type name.
  2. The result appears straight away and updates as you edit.
  3. Copy the result, or copy a link that keeps the same values to share it.

How it is calculated

integer for whole numbers, number for decimals, string and boolean, array with items, and object with properties. Keys present in every array item go into required, null adds "null" to type, and mixed values become {} (any value).

Example

Inputs: Root type name = Root. Result: Generated code: { "$schema": "https://json-schema.org/draft/2020-12/schema", "title": "Root", "type": "object", "properties": { "id": { "type": "integer" }, "name": { "type": "string" }, "email": { "type": "string" }, "is_active": { "type": "boolean" }, "balance": { "type": "number" }, "tags": { "type": "array", "items": { "type": "string" } }, "address": { "type": "object", "properties": { "city": { "type": "string" }, "postal_code": { "type": "string" } }, "required": [ "city", "postal_code" ] }, "orders": { "type": "array", "items": { "type": "object", "properties": { "order_id": { "type": "string" }, "total": { "type": "number" }, "coupon": { "type": [ "string", "null" ] } }, "required": [ "order_id", "total", "coupon" ] } } }, "required": [ "id", "name", "email", "is_active", "balance", "tags", "address", "orders" ] }; Types generated: 3; Fields: 13.

{
  "id": 1024,
  "name": "Sara Ahmed",
  "email": "sara@example.com",
  "is_active": true,
  "balance": 1520.75,
  "tags": ["vip", "riyadh"],
  "address": { "city": "Riyadh", "postal_code": "12211" },
  "orders": [
    { "order_id": "A-1", "total": 99.5, "coupon": "EID10" },
    { "order_id": "A-2", "total": 120, "coupon": null }
  ]
}
{
  "$schema": "https://json-schema.org/draft/2020-12/schema",
  "title": "Root",
  "type": "object",
  "properties": {
    "id": {
      "type": "integer"
    },
    "name": {
      "type": "string"
    },
    "email": {
      "type": "string"
    },
    "is_active": {
      "type": "boolean"
    },
    "balance": {
      "type": "number"
    },
    "tags": {
      "type": "array",
      "items": {
        "type": "string"
      }
    },
    "address": {
      "type": "object",
      "properties": {
        "city": {
          "type": "string"
        },
        "postal_code": {
          "type": "string"
        }
      },
      "required": [
        "city",
        "postal_code"
      ]
    },
    "orders": {
      "type": "array",
      "items": {
        "type": "object",
        "properties": {
          "order_id": {
            "type": "string"
          },
          "total": {
            "type": "number"
          },
          "coupon": {
            "type": [
              "string",
              "null"
            ]
          }
        },
        "required": [
          "order_id",
          "total",
          "coupon"
        ]
      }
    }
  },
  "required": [
    "id",
    "name",
    "email",
    "is_active",
    "balance",
    "tags",
    "address",
    "orders"
  ]
}

Limits and caveats

  • It adds no constraints such as minLength, format or enum, so add them by hand.
  • Nested objects are written inline, without $defs.

Questions about this tool

integer or number?

integer accepts whole numbers only, number accepts any number. If any item holds a decimal, the key becomes number.

How is required decided?

A key present in every array item is required even if its value is null; a key missing from some items is left out.

Does it work with Ajv?

Yes. Use Ajv2020, because the schema declares draft 2020-12 in $schema.