JSON Type Generator

Generate JSON Schema from a JSON sample automatically

Shortcuts: Ctrl+Enter run · Ctrl+L clear · Ctrl+D download

About JSON Type Generator

JSON Type Generator infers a JSON Schema from a JSON sample automatically. Instead of writing a schema by hand, paste a representative JSON document and get a complete Draft 7 JSON Schema describing its structure, types, and required fields. Use the output directly with JSON Schema validators or as a starting point to add custom constraints.

  • ✓Infers types (string, number, boolean, null, array, object) from sample values
  • ✓Marks every key with a non-null sample value as required
  • ✓Handles nested objects and arrays recursively
  • ✓Produces a valid JSON Schema Draft 7 document ready to use with ajv or similar libraries

Generating a JSON Schema from an Example

A JSON Schema is a machine-readable description of what a JSON document should look like: which fields exist, their types, and which are required. Writing one by hand for a large payload is tedious. This tool infers a draft-07 schema from a sample document, giving you a solid starting point that you then tighten by hand.

What gets inferred

  • ·Objects become "type": "object" with a properties entry for every key
  • ·Every key with a non-null value is added to required; keys whose sample value is null are left optional
  • ·Numbers are typed as integer or number depending on whether the sample has a fractional part
  • ·Strings that look like a date (2026-10-10), a date-time, an email address or an http(s) URL get a matching format
  • ·Array items are inferred from the elements; if the elements have different types, the schema lists the alternatives with oneOf
  • ·For an array of objects, the item schema is taken from the first element, so put your most complete record first

Example

// Sample
{ "id": 7, "email": "ada@example.com", "score": 9.5, "tags": ["a"], "manager": null }

// Generated (abridged)
{
  "$schema": "http://json-schema.org/draft-07/schema#",
  "type": "object",
  "properties": {
    "id": { "type": "integer" },
    "email": { "type": "string", "format": "email" },
    "score": { "type": "number" },
    "tags": { "type": "array", "items": { "type": "string" } },
    "manager": { "type": "null" }
  },
  "required": ["id", "email", "score", "tags"],
  "title": "Root"
}

Review it before you rely on it

A schema inferred from one example can only describe that example. Before using it to validate real traffic, check a few things:

  • ·Required fields: a key present in your sample may be optional in practice — remove it from required if so
  • ·Nullable fields: manager above is typed as null only; if it can also hold an object, change it to allow both
  • ·Integer vs number: a price that happened to be 10 in the sample will be typed integer, then reject 10.5 later
  • ·Enums and limits: add enum, minimum, maxLength and similar constraints that no example can reveal
  • ·Extra keys: add "additionalProperties": false if unexpected fields should be rejected

What to do with the schema

Use it with the JSON Schema Validator on this site to check documents against it, add it to your API documentation (OpenAPI uses a very similar schema dialect), or feed it to a code generator. If what you actually want is TypeScript interfaces, the JSON to TypeScript tool generates those directly.

Tip: Paste a sample that includes as many optional fields as possible — the more complete the example, the less you will need to edit afterwards.

Frequently Asked Questions

Ad