Skip to content
yutils
Example

Input (sample JSON)

{
  "id": 1,
  "name": "Alice",
  "active": true,
  "tags": ["admin", "user"]
}

Output (Draft 2020-12 Schema)

{
  "$schema": "https://json-schema.org/draft/2020-12/schema",
  "type": "object",
  "properties": {
    "id": { "type": "integer" },
    "name": { "type": "string" },
    "active": { "type": "boolean" },
    "tags": {
      "type": "array",
      "items": { "type": "string" }
    }
  },
  "required": ["id", "name", "active", "tags"]
}

Note

Schema inferred from a single sample. Every observed field is marked required — remove optional ones manually, or merge schemas from multiple samples.

Usage / FAQ

When to use

  • Extract a schema from an API response sample (Swagger / OpenAPI starter)
  • Convert existing JSON data to a schema for validation rollout
  • Learn JSON Schema by comparing input and output side-by-side
  • Auto-generate schemas for test fixtures
  • First step in a JSON → ts → schema workflow (pair with json-to-ts)

FAQ

Q.Which Draft is produced?
A.Draft 2020-12 — same as the JSON Schema Validator pair tool. The result includes a `$schema` URL.
Q.Why is every field marked required?
A.Single-sample inference can't tell which fields are optional, so every observed field is required. Remove optional ones manually after generation.
Q.Does it detect format (email, uri, date)?
A.Only base type inference for now — no pattern detection for email / uri / date. Add `format` constraints manually, then verify with the JSON Schema Validator pair tool.
Fun facts
  • The hardest call when inferring schema from sample JSON is 'optional vs required.' A single sample makes every key look required, but real-world keys are often nullable or optional. Good generators take multiple samples and use key-presence frequency to infer optionality.

    JSON Schema — Getting started
  • JSON Schema 2020-12 added `prefixItems` for tuple-like arrays (each index a different type). Earlier drafts overloaded `items` (array form) for this purpose, but it was ambiguous — 2020-12 cleanly separated the intent.

    JSON Schema 2020-12
  • OpenAPI 3.1 (2021) is fully compatible with JSON Schema 2020-12. Through 3.0, OpenAPI had its own dialect; 3.1's decision to fully adopt JSON Schema unified tooling — validators like ajv now check OpenAPI directly.

    OpenAPI 3.1