UtilityKit

500+ fast, free tools. Most run in your browser only; Image & PDF tools upload files to the backend when you run them.

JSON Schema Generator from Sample

Automatically infer a JSON Schema from a sample JSON document to bootstrap schema development.

About JSON Schema Generator from Sample

The JSON Schema Generator from Sample analyzes a JSON document and automatically infers a JSON Schema that describes its structure. It detects property names, types (string, number, integer, boolean, array, object, null), required fields (present in all objects of the same shape), array item schemas, and nested object schemas — producing a complete Draft-07 or Draft-2020-12 compatible JSON Schema as a starting point. The generated schema is then ready to be refined by hand: adding descriptions, enum constraints, minLength/maxLength rules, or format annotations. This eliminates the tedious manual work of writing schemas from scratch when you already have sample data.

Why use JSON Schema Generator from Sample

  • Generates a complete JSON Schema skeleton in seconds from real data.
  • Infers required fields, array item schemas, and nested object structure.
  • Supports Draft-07 and Draft-2020-12 output formats.
  • Dramatically reduces the manual work of bootstrapping schema development.
  • Generates a complete JSON Schema skeleton in seconds from real data — no manual writing.
  • Infers required fields, array item schemas, and nested object structure automatically.

How to use JSON Schema Generator from Sample

  1. Paste your sample JSON document into the input panel.
  2. Select the desired JSON Schema draft version (Draft-07 or Draft-2020-12).
  3. Click Generate — the inferred schema appears in the output panel.
  4. Copy and refine the schema in your codebase or the JSON Schema Validator.
  5. Provide multiple example objects in an array to merge inferred schemas across samples.
  6. Toggle 'strict mode' to set additionalProperties: false on every object — useful for tight contracts.
  7. Copy and refine the schema in your codebase, then validate against new data with the JSON Schema Validator.

When to use JSON Schema Generator from Sample

  • Bootstrapping a JSON Schema for an existing API that lacks documentation.
  • Creating a starting schema from a sample API response to validate against.
  • Generating schemas for configuration files to enable editor validation.
  • Documenting data structures for team sharing or API contracts.
  • Creating a starting schema from a sample API response to validate against in tests.
  • Generating schemas for configuration files to enable editor validation (VSCode, IntelliJ).

Examples

Simple user object

Input: { "id": 1, "name": "Ada", "email": "ada@example.com", "active": true }

Output: { "$schema": "http://json-schema.org/draft-07/schema#", "type": "object", "required": ["id", "name", "email", "active"], "properties": { "id": { "type": "integer" }, "name": { "type": "string" }, "email": { "type": "string", "format": "email" }, "active": { "type": "boolean" } } }

Array of items

Input: { "tags": ["alpha", "beta", "gamma"] }

Output: tags: { type: 'array', items: { type: 'string' } }

Multi-sample merge

Input: [ { id: 1, name: 'A' }, { id: 2, name: 'B', archived: true } ]

Output: Required: ['id', 'name'] (archived only present in second sample, becomes optional).

ISO date-time detection

Input: { "createdAt": "2024-05-08T14:30:00Z" }

Output: createdAt: { type: 'string', format: 'date-time' } — ISO 8601 pattern detected.

Tips

  • Provide multiple sample objects (as an array) to make required-field inference more accurate — fields present in only some samples will become optional.
  • After generation, manually add 'description' fields to every property — they appear in IDE tooltips and improve developer experience hugely.
  • Set additionalProperties: false on objects that should reject unknown keys — the generator can do this with the strict-mode toggle.
  • Replace inferred string types with enum where the value set is closed (e.g. status: 'active' | 'archived').
  • Add minLength, maxLength, minimum, maximum, pattern constraints based on your domain knowledge — the generator infers structure but not business rules.
  • Before publishing the schema, validate it against your sample data using the JSON Schema Validator — catch any gaps from the inference.

Frequently Asked Questions

Is the generated schema production-ready?
The schema accurately reflects the structure of the sample data but is intentionally permissive. You should add constraints (minLength, enum, format, additionalProperties: false) before using it in production.
How does it determine which fields are required?
Fields present in every object of the same shape across the sample are marked as required. Fields that appear only sometimes are treated as optional.
Does it handle arrays with mixed types?
Arrays with mixed types produce a schema with anyOf or a union type. Homogeneous arrays produce a typed items schema.
Can I provide multiple sample objects?
Yes. Paste a JSON array of multiple example objects and the generator will merge the inferred schemas to produce a more comprehensive result.
Does it infer format keywords like date-time or email?
The generator detects common string patterns and adds format hints (date-time, email, uri) where the sample values match. These are suggestions, not guarantees.
Why does my schema mark a field as 'integer' when sometimes it's a float?
Type inference looks at each sample. If the only samples are whole numbers, the inferred type is 'integer'. Provide a sample with a decimal value to widen it to 'number'.
How do I close the schema to reject unknown fields?
Enable strict mode in the tool, or manually add 'additionalProperties': false to every object. This turns a permissive contract into a strict one.
Can I generate Draft-2020-12 even if my tooling supports only Draft-07?
Yes, but most differences are subtle. If your downstream tooling (Ajv, OpenAPI 3.0) only supports Draft-07, generate Draft-07 to avoid keyword incompatibility surprises.

Explore the category

Glossary

Schema inference
The process of analyzing data and deriving a structural description (schema) from it. The output describes the shape of the data but not its semantic constraints.
Required vs optional
In JSON Schema, properties listed under 'required' must be present. Properties under 'properties' but not in 'required' are optional. Inference marks fields present in all samples as required.
Draft-07
A widely adopted JSON Schema specification version. Most tooling (Ajv, AsyncAPI 2.x, OpenAPI 3.0) supports it natively.
Draft-2020-12
The current JSON Schema specification. Adds prefixItems, refined $ref behavior, and unevaluatedProperties. Recommended for new projects when tooling supports it.
additionalProperties
Schema keyword that controls whether objects may contain unknown properties. Set to false for strict contracts; set to a schema to validate unknown properties.
Type coercion
JSON Schema does not coerce types. The inferred type from sample '5' (string) will be 'string', not 'number'. Refine manually if the runtime should treat it as numeric.
Format keyword
Annotates strings with semantic types (email, uri, date-time, uuid). Inferred from common value patterns; validation may be assertive or informational.
Heterogeneous array
An array containing items of different types. Inferred as anyOf or a union type, since each item must satisfy at least one schema option.