Skip to content
UniKit

JSON to JSON Schema

Infer a draft 2020-12 JSON Schema from sample JSON — objects, arrays and primitives — with all / common / none required strategies, optional inline examples and a compact one-line output.

Runs in your browserEvery computation happens in your browser — your data never leaves this device.

Sample JSON

Only text that JSON.parse accepts is allowed. Control optionality with the required strategy below instead of guessing from several samples.

JSON Schema

The output targets draft 2020-12 and every object gets additionalProperties: false.

Enter JSON to see the schema

Top-level keys: 0 · Properties: 0

What this tool does

  • Draft a schema for a sample API response that you can paste into a validator such as Ajv
  • Turn real production data into documentation of field types and nesting
  • Compare the three required strategies to decide which fields are truly mandatory

Example

Input

{"id":1}

Output

{
  "$schema": "https://json-schema.org/draft/2020-12/schema",
  "type": "object",
  "properties": {
    "id": {
      "type": "integer"
    }
  },
  "required": [
    "id"
  ],
  "additionalProperties": false
}

Defaults are required=all, no inline examples and pretty printing: the integer maps to "integer", every observed key lands in required, and objects carry additionalProperties: false.

Frequently asked questions

How do the three required strategies differ?

all (the default) marks every key that appeared as required; common marks only keys present in every sample, which is handy for arrays of objects where the intersection is the real requirement; none omits required entirely. For a single object sample, all and common agree.

Why does every object get additionalProperties: false?

That is this tool's deliberate choice: it generates a strict schema so unexpected fields surface early. JSON Schema itself allows extra properties by default, so if your API tolerates them, delete that line or set it to true.

Can it infer fields that never appear in the sample?

No. The schema only reflects what the sample shows: an optional field that happens to appear everywhere will be marked required by the all strategy, and value ranges, formats (dates, emails) and enums cannot be inferred at all. Loosen required with common/none and add format, pattern or enum by hand.

How are arrays and mixed types handled?

A uniform element type goes straight into items; mixed elements such as [1, "a"] produce items.anyOf listing every observed type; when all elements are objects their fields are merged into one object schema, and a field with different values in different elements gets its own anyOf. An empty array produces items: {}.

Keywords:JSON Schemajson-to-schemaschema generator

Related tools