toolgarden.xyz
中文

JSON Schema Generator

Free online JSON Schema generator that automatically infers a schema from a sample JSON / JSONC / JSON5 document

Input JSON / JSONC / JSON5 Sample

JSON Schema

Schema will appear here

About this tool

JSON Schema describes allowed JSON types and structures as machine-readable rules. The generator walks a sample, creates object properties and required lists, infers array items, and distinguishes integer, number, boolean, null, plus common date, email, and URI string formats.

A sample proves what appeared once, not every valid case. The generated Draft 2020-12 schema marks observed object fields as required and may use oneOf for differing array samples. Optional fields, ranges, enums, and additionalProperties still need business review.

How to use it

  1. Choose a representative sample

    Include typical fields, array members, and boundary values rather than one unusually simple record.

  2. Generate the base schema

    The tool recursively infers types and properties and emits JSON identified as Draft 2020-12.

  3. Add contract rules

    Adjust required, enum, format, numeric ranges, and extra-property behavior, then test it with the validator.

Input and output example

A schema inferred from a sample. It captures fields and types but no required and no ranges; those are yours to add.

JSON sample
{ "id": 7, "name": "kit" }
Generated schema
{
  "type": "object",
  "properties": {
    "id": { "type": "integer" },
    "name": { "type": "string" }
  }
}

Supported range and limits

Output
A JSON Schema definition inferred from a JSON sample
What it infers
Field names, types, nesting, and array element types
What it cannot infer
Whether a field is required, value ranges, string formats such as email or date, and enum values; all added by hand
Single-sample limits
Fields missing from the sample never enter the schema, and optional fields look required
Suggested workflow
Generate from several representative samples, merge and add required plus constraints by hand, then verify with Schema Validator
Used for
Seeding API contracts, config validation and form validation

When you would use it

  • Adding a contract to an API

    Create a schema skeleton from an existing response for validation, documentation, and fixture checks.

  • Reviewing configuration shape

    Turn a known-good config into explicit rules that catch misspelled fields and unexpected types.

  • Drafting validation rules for a front-end form

    Infer fields and types from one submitted example, then add required, length and format constraints as the starting point for form validation.

What to know before you start

  • Observed object fields are marked required even though the real service may treat some as optional.
  • An empty array contains no item evidence, so its items schema cannot be constrained automatically.
  • String format detection is heuristic; ordinary text resembling a date or email can receive a format keyword.

Related concepts

Draft 2020-12
A widely used JSON Schema specification version defining keyword behavior and the meta-schema URI.
required
An array of property names that must exist on an object, separate from whether their values may be null.

Frequently asked questions

How is the JSON Schema generated?
The tool analyzes the JSON sample you provide, infers each field's type and structure, and produces a matching JSON Schema definition.
Do I need to tweak the generated schema?
Usually yes. A sample can't express optional fields, value ranges or the real type behind null, so add constraints like required and enum as needed.
Does generating upload my data?
No. Schema inference runs locally in your browser and the sample is never uploaded.
Can I use the generated schema as-is?
Not advisable. It captures only what a sample reveals; field names, types, structure; and omits required, ranges, string formats and enums, which is precisely where validation earns its keep. Treat it as a draft and finish it by hand.
How do I build a fuller schema from several samples?
Generate one schema per representative sample, then merge by hand: fields present in every sample go into required, fields present in only some stay optional, and conflicting types become unions. Finally regression-test every sample with Schema Validator.