Home Tools Blog About

JSON Schema Generator

In short

Infers a JSON Schema from one or more sample documents, detecting required keys, nullable values and formats like email and date-time, and validates JSON against it.

  • Runs in your browser
  • Nothing uploaded
  • Free, no sign-up

Paste one JSON document, or several separated by a blank line. More samples give better required fields and types.

Validate JSON against this schema

Need TypeScript types from the same JSON? Try JSON to TypeScript. To tidy the sample first, use the JSON Formatter.

Your JSON is processed in this tab; it is not uploaded.
🛡
Private by designYour files and text stay in this tab
⚡
Runs in your browserNo waiting for a server
💧
No watermarksClean output you can use
🆓
FreeNo account needed

How to Use JSON Schema Generator

JSON Schema Generator · free online tool · All Tools Verse
The JSON Schema Generator tool, as it looks in your browser.
  1. Paste sample JSON. Add several samples separated by a blank line; keys missing from some samples become optional.
  2. Pick the draft and options. Choose 2020-12, 2019-09 or draft-07, which keys are required, and whether to detect formats or allow extra properties.
  3. Edit if you like. The schema box is editable, so you can add limits like minimum or maxLength.
  4. Validate. Open "Validate JSON against this schema", paste a document and see each problem with its JSON path.

Example: two user records

The Sample holds two user objects. The second has no address field, and its website is null. From them the generator writes (properties shortened here):

{
  "$schema": "https://json-schema.org/draft/2020-12/schema",
  "type": "object",
  "required": [
    "id",
    "email",
    "name",
    "role",
    "signedUp",
    "website",
    "score",
    "tags"
  ]
}

Inside properties, the details it found include:

  • id: {"type": "integer"}
  • email: {"type": "string", "format": "email"}
  • signedUp: {"type": "string", "format": "date-time"}
  • website: {"type": ["string", "null"], "format": "uri"}, because one sample had a URL and the other null
  • score: {"type": "number"}, because 98.5 and 87 mix decimals and whole numbers

address is not in the required list, since only one sample had it. Validating the sample test document then reports 3 problems:

Where Problem
(root) Missing required property "website".
/id Expected integer, got string.
/email Not a valid email.

What each JSON value becomes

In your sample In the schema
42 “type”: “integer” (or “number” if you untick whole numbers)
3.14, or a mix of 3 and 3.5 “type”: “number”
“[email protected]” “type”: “string”, “format”: “email”
“2024-03-18T09:30:00Z” “format”: “date-time”
“2024-03-18” “format”: “date”
“https://example.com” “format”: “uri”
A value that is null in some samples “type”: [“string”, “null”]
[] or [“a”, “b”] “type”: “array”, “items”: {…}
A key missing from some samples Left out of “required”

How it works

Every sample is walked value by value, and the types seen at each path are counted. A key is required when it appears in every object at that path. A string gets a format only if every value seen there matches that format, so one odd value keeps the schema loose instead of wrong. The $schema line follows the draft you pick: 2020-12 and 2019-09 use https://json-schema.org/draft/…, draft-07 uses http://json-schema.org/draft-07/schema#.

The built-in validator covers the keywords people use most: type, required, properties, additionalProperties, items and prefixItems, enum, const, string and number limits, pattern, format, uniqueItems, allOf, anyOf, oneOf, not and local $ref. During testing its results matched the Python jsonschema library on every draft-07 test case.

Limits

  • A schema guessed from samples only knows what the samples show. Review it, and add enums, ranges and patterns that reflect your real rules.
  • The validator does not follow $ref to other files or URLs, and does not support if/then/else or dependentSchemas.
  • Draft 2019-09 and 2020-12 differ from draft-07 in a few keywords (for example $defs instead of definitions, and prefixItems for fixed-position arrays). The generated schemas use only keywords that mean the same in all three.

Frequently asked questions

Which JSON Schema draft should I use?

Use 2020-12 for new projects. Pick draft-07 if your validator or framework is older; it is still the version many libraries support best.

How do I make a field optional in JSON Schema?

Leave it out of the “required” list. The generator does this automatically for keys that are missing from at least one sample, so paste a few real examples.

How do I allow null in JSON Schema?

Use a type list such as “type”: [“string”, “null”]. The generator writes that when a key is null in some samples and has a value in others.

Can I generate a schema from a JSON array?

Yes. An array becomes “type”: “array” with an items schema. Tick “Top-level array = list of samples of one item” if the array is a list of records and you want the schema for one record.

Keep going

Related Tools

All Seo tools →

Article Schema Generator →

Generate Article, NewsArticle, or BlogPosting schema markup instantly. Get rich results in Google Search.…

Event Schema Generator →

Generate Schema.org Event JSON-LD - physical, virtual, or mixed events with attendance mode, offers,…

FAQ Schema Generator →

Build Schema.org FAQPage JSON-LD from Q&A pairs. Pretty, compact, or script-tag formats. Free, offline,…

Job Posting Schema Generator →

Build JobPosting structured data for Google Jobs with salary, location or remote, employment type,…

Local Business Schema Generator →

Build LocalBusiness structured data with address, map coordinates, opening hours, and social links, with…

Product Schema Generator →

Build Product structured data with price, availability, brand, and review ratings, and copy clean…

Recipe Schema Generator →

Build Recipe structured data with ingredients, step by step instructions, times, and ratings, and…

Schema Markup Extractor →

Finds the structured data in a page's HTML (JSON-LD, Microdata and RDFa), shows each…

Schema Markup Generator →

Generate JSON-LD for Article, Organization, Person, Event, WebSite, Breadcrumb, and FAQ from one studio,…

Analyze JSON Online and Validate JSON Structure →

Analyze JSON Online Validate & Analyze JSON Structure with detailed statistics including depth, key…

Android AssetLinks JSON Generator - App Links →

Android AssetLinks JSON Generator files for Android App Links. Configure package names and SHA-256…

Convert BSON to JSON →

Convert MongoDB BSON hex dumps to readable JSON in your browser. Free, offline, client-side…

Share

Embed this tool

Add this free tool to your website. Copy and paste the code: