Skip to content

JSON to JSON Schema Converter — Numio

Infers a JSON Schema (draft-07) from a JSON sample. For arrays of objects, all elements are merged: a key missing from or null in some elements is left out of required.

Creating a first validation schema for an API response or webhook payload from captured examples.

JSON

JSON Schema

When to use it

  • Creating a first validation schema for an API response or webhook payload from captured examples.
  • Producing a schema to feed into Ajv, OpenAPI or a JSON Schema to TypeScript/Zod step.

How to use

  1. Paste a JSON sample into the left editor, or use the load-file button to open a UTF-8 file. An array of several records gives better required lists.
  2. Read the schema: every key in a single object is required, and keys absent or null in some array elements are optional.
  3. Copy the schema and add constraints the sample cannot show, such as formats, enums, integer and minimum.

JSON sample

[
  { "id": 1, "name": "Ada", "email": null },
  { "id": 2, "name": "Lin", "email": "lin@example.com" }
]

JSON Schema (draft-07)

{
  "$schema": "http://json-schema.org/draft-07/schema#",
  "title": "Generated schema for Root",
  "type": "array",
  "items": {
    "type": "object",
    "properties": {
      "id": {
        "type": "number"
      },
      "name": {
        "type": "string"
      },
      "email": {
        "type": "string"
      }
    },
    "required": [
      "id",
      "name"
    ]
  }
}

Details and limitations

Numbers are always "type": "number"; integer, formats (email, date-time), enums and patterns are not inferred. The title is always "Generated schema for Root".

A field that is null everywhere gets an empty schema {}. A null that sits beside other values is treated as optional, not as type null.

Mixed-type arrays such as [1, "x"] become a tuple (items list with additionalItems: false); an empty array gives items: {}.

Generated in your browser by json_typegen compiled to WebAssembly. Invalid JSON (including trailing commas) shows the JSON parse error, and a single value such as 42 is rejected because it has no structure.

FAQ

Which JSON Schema draft does it output?

Draft-07, declared as "$schema": "http://json-schema.org/draft-07/schema#". There is no option to choose 2019-09 or 2020-12.

How are optional fields detected?

Only across elements of the same array: a key missing from some objects, or null in some, is left out of required. In a single object every key is required.

Can it convert a JSON array at the root?

Yes. The root gets "type": "array" and the elements are merged into one items schema, as in the example.

Specifications and references