Shard Tools

JSON to JSON Schema

Generate a JSON Schema from a sample document in your browser, inferring types and required fields.

Maintained by Roshan.

Use JSON to JSON Schema

Converts json sample to json schema in this tab, with nothing sent anywhere.

Runs entirely on your deviceThe conversion happens in this browser tab. Nothing you type is uploaded, logged or stored, which is worth knowing for anything you would not paste into a search box.

Explore generators

Find related browser-local tools for nearby tasks without starting another search.

Browse all generators

About JSON to JSON Schema

JSON Schema is how you describe and validate the shape of JSON - what fields exist, what types they hold, which are required - and writing one by hand from scratch is laborious. Generating a draft from an example document gives you a running start: paste a representative sample, and get a schema that matches it. This infers the type of every value, distinguishes an integer from a decimal where the sample makes that clear, and lists the fields present as required, producing a valid draft 2020-12 schema. It is a starting point rather than a finished contract - a real schema usually needs constraints the sample cannot imply, such as string formats, number ranges, or which fields are genuinely optional - but it removes the tedium of typing out the structure and leaves you to add the rules that matter.

Using JSON to JSON Schema

  1. The sample document is parsed and walked recursively.
  2. Each value's type is inferred, with an integer distinguished from a decimal number where the sample shows a whole number.
  3. Every property present in an object is listed under required, since the sample contains it.
  4. Nested objects and arrays are described with their own nested schemas.
  5. The result is a valid JSON Schema against the 2020-12 draft, with the schema declaration included.

Where json to json schema helps

Documenting an API's shape

Paste a representative response and get a schema draft. Then trim the required list and add formats and ranges.

Setting up validation

Generate the schema from sample data, then tighten it with the constraints your validation needs to enforce.

Before you use the result

Questions about JSON to JSON Schema

Which draft does it target?

JSON Schema draft 2020-12, with the schema declaration included in the output.

Why is everything required?

Because the sample contains every field. Remove from the required list the fields that are genuinely optional.

Does it add formats or ranges?

No. A sample cannot imply those. Add string formats, number ranges and patterns yourself.

Does it tell integers from decimals?

Yes, where the sample shows a whole number it uses 'integer'; a decimal uses 'number'.

Related tools

JSON to TypeScript

Generate TypeScript interfaces from a JSON sample in your browser. Nested objects become their own interfaces.

JSON Formatter and Validator

Format, minify, and validate JSON locally in your browser. Inspect keys, values, nesting depth, and root type without sending private API data to a server.

JSON to Go Struct

Generate Go structs from a JSON sample in your browser, complete with json struct tags.