Skip to content
Simple Tools

Practical guide

How to generate JSON Schema from a data sample

An API response sample shows one dataset, not the entire contract. This guide explains how to read the generated schema and which decisions to make before using it to validate real responses.

Simple Tools editorial teamReviewed: 2 October 2026

Choose a representative sample and object policy

Paste anonymized JSON, choose an additional-member policy and select “Process”. The default allows new members. Closed mode adds additionalProperties: false to every inferred object, including nested objects. The decision applies throughout the sample; the tool does not assign separate policies to individual paths.

Output declares JSON Schema 2020-12. It is a working document, not an automatically approved contract. The generator does not validate the sample or subsequent data, fetch remote schemas or generate $ref. Application use needs a compatible validator and review by the API owner.

Read properties, required and type

Every observed object member becomes required. Ordering within required may differ from input without changing meaning. Null gives type null, not an automatic string | null union. A string date remains string. Every number infers number, including whole-number samples.

The table shows a default open-object schema. Value 1.5 can satisfy number even though the sample contains 1; a missing city member cannot satisfy required. If the contract permits optional members, revise the schema and test both cases. One sample cannot establish which members are always present.

Working schema with additional members allowed
JSON sampleJSON Schema 2020-12
{"city":"Łódź","count":1}{ "$schema": "https://json-schema.org/draft/2020-12/schema", "type": "object", "properties": { "city": { "type": "string" }, "count": { "type": "number" } }, "required": [ "city", "count" ], "additionalProperties": true }
[]{ "$schema": "https://json-schema.org/draft/2020-12/schema", "type": "array", "items": {} }

Arrays, anyOf and empty structures

Different array-item shapes form anyOf, allowing at least one described alternative. Objects {"a":1} and {"b":true} remain separate alternatives requiring a or b. They do not automatically become one object with optional members. Member order in an equivalent object does not create another shape.

An empty array gives items: {}, leaving item types unconstrained. An empty object has no properties: open mode allows members and closed mode does not. Do not infer item types from a member name. Add representative examples and consult documentation rather than treating missing sample data as confirmed permissiveness.

What can a sample not establish?

The generator does not infer date formats, numeric ranges, enum, member dependencies, business rules or string-length limits. A name email does not add format: email. These decisions need system requirements rather than guesses from one value. Add rules deliberately and check your chosen validator’s behavior.

A number schema does not solve large-number handling in JavaScript. Although input tokens are parsed without rounding, a receiver or validator may already have a changed value. Agree identifier and exact-amount types with the contract. Do not stringify data merely to make a test pass.

Test the contract and recognize limits

Check the schema with an independent validator supporting 2020-12. Prepare expected-valid and expected-invalid data: missing required members, changed types, additional members in closed objects and every array alternative. Confirm results against API documentation. Passing the original sample is insufficient to approve the contract.

Input is capped at 50,000 UTF-16 units and 10,000 values. Inference allows 32 container levels and 64 distinct shapes per array; output is limited to 500,000 units. Errors produce no partial schema. Reduce a complete sample while retaining necessary alternatives; simplification should not hide API rules.

Privacy, copying and reset

For conversions and schemas, use short anonymized samples instead of production exports. Input and output are processed in the browser without sending them to analytics or keeping history in localStorage or sessionStorage. Page loading still connects your device to hosting. Extensions and clipboard contents remain outside this protection.

Editing clears the old result; select “Process” again. Copying is a separate action. “Clear” restores the form and initial options but cannot remove earlier copies, saved files or printouts. When reporting an issue, include a short synthetic example, selected options and expected output. Do not include secrets or customer data.

Frequently asked questions

Is the generator a data validator?

No. It creates a working schema from a sample. Validate separately with a compatible tool.

Are members automatically optional?

No. All observed members are required; differing array shapes form anyOf.

What does empty items: {} mean?

It does not restrict item types. An empty sample does not establish the contract’s intended type.

Does clearing remove the clipboard copy?

No. The form is reset; earlier clipboard copies, files or printouts need separate removal.

Sources and scope

Examples are synthetic. Limits and supported options describe this site’s tools, not the full standards. Check output in its destination system. This guide does not establish API-contract compliance, configuration security or business-rule correctness.

Tools covered by this guide

Generator

UUID and GUID generator

Generate 1–100 UUIDv4 identifiers using Web Crypto randomness, locally and without a timestamp.

Generator

JSON to YAML converter

Convert JSON into readable YAML with quoted strings, no anchors and unchanged number tokens.

Generator

YAML to JSON converter

Read a single YAML 1.2 document and produce JSON without alias expansion or lost large numbers.

Generator

JSON Schema generator

Create a working JSON Schema 2020-12 from a sample with an explicit additional-object-members policy.