JSON Input JSON
โš ๏ธ Invalid JSON โ€” please check your input.
JSON Schema Output SCHEMA
Advertisement
What does a JSON to JSON Schema generator do? A JSON to JSON Schema generator reads a sample document and writes a schema describing its shape. This one infers type, integer versus number, required keys, a few string formats such as email and date, and examples from the values you paste. It reads only one sample and sets no minimums, maximums or enums.

What does a JSON to JSON Schema generator do?

A JSON Schema describes what valid JSON looks like: which keys exist, what type each value has, and which ones are required. Writing one from scratch for a large response is slow, so many developers start from a real sample and edit the result.

This JSON to JSON Schema generator walks through your sample and records what it sees. Strings, numbers (as integer when whole), booleans and null each get a type. Objects get properties and, optionally, a required list. Arrays get an items schema. Four checkboxes control the rest: Mark all fields required, Include examples from input, Allow null on all fields and additionalProperties: false.

The limits matter. An array is described by its first element only, so a list of mixed objects is not merged. Optional fields cannot be detected from one sample, because every key you give is treated as present. And the Draft menu only changes the $schema address, which is Draft-07 or 2020-12. Think of the output as a scaffold. Before you validate real data, check the shape with the JSON formatter, and refine the schema by hand. For other formats see YAML to XML.

How to generate a JSON Schema from JSON

  1. Paste a representative JSON document into JSON Input, or click Sample.
  2. Choose Draft: Draft-07 or Draft 2020-12.
  3. Set the checkboxes: Mark all fields required, Include examples from input, Allow null on all fields, additionalProperties: false.
  4. Click Generate Schema. Invalid JSON shows a red warning.
  5. Edit the schema: remove optional keys from required, add enums, ranges and patterns.
  6. Use Copy, or Download schema.json to save it.

What the generated schema contains

Type inference

Whole numbers become integer, other numbers become number, and strings, booleans and null get their own types.

Required list

With the checkbox on, every key present in an object is listed in required at every nesting level.

Format guesses

A string that looks like an email, an ISO date, an ISO date-time or an http(s) URL gets format of email, date, date-time or uri.

Examples

Each string, number or boolean gets an examples array holding the value from your sample.

Nullable option

Turns string, number and boolean types into a list such as ["string","null"]. Objects and arrays are left unchanged.

Closed objects

Adds additionalProperties: false to every object, so extra keys fail validation.

When to generate a schema from a sample

  • Documenting an API response. Paste a real response and get a first schema you can drop into your docs or an OpenAPI file, then tighten it.
  • Validating config files. Create a schema from a known-good settings file, then edit it so editors can flag mistakes in similar files.
  • Creating test contracts. Teams can generate a schema from an example payload and use it in a contract test between two services.
  • Learning JSON Schema. Beginners see how a sample object maps to properties, required and items.

Tips: what to fix after generating

  • Use a sample with every optional key present, then delete the truly optional ones from required.
  • Put at least one element in each array. An empty array produces "items": {}, which accepts anything.
  • Mixed arrays are described by the first item. If items vary, merge schemas by hand with anyOf.
  • Remove examples you do not want published, as they copy values from your sample, including any private ones.
  • Format is a hint, not a guarantee. Many validators ignore format unless told to check it.

Is it safe? Privacy and limits

The schema is built by JavaScript in your browser. The JSON you paste is not uploaded, and no account is required. Because examples are copied from your sample, the output can contain real values, so use fake data or switch the examples option off before sharing the schema. Generated schemas are drafts and have not been tested against any validator.

JSON to JSON Schema FAQ

Only the $schema line at the top. Draft-07 uses http://json-schema.org/draft-07/schema# and Draft 2020-12 uses https://json-schema.org/draft/2020-12/schema. The keywords inside, such as type, properties, required, items and examples, are written the same way for both. That keeps the output compatible with most validators. If you plan to use newer keywords like prefixItems, $defs or unevaluatedProperties, you add them by hand. That is why the output is easy to move between tools.

One sample cannot show which fields are optional, so the tool assumes any key you gave is expected. The Mark all fields required box is on by default for that reason. Untick it to leave out the required lists entirely, or keep it on and delete the optional names from each required array afterwards. A good method is to compare two samples, one minimal and one full, and keep as required only the keys in both.

It looks at the first element only and uses its shape as the items schema. If your array has objects with different keys, the keys that appear only in later elements are not included in the schema at all. For an array of mixed things, add an anyOf list by hand. An empty array gives an empty items schema, meaning any value is allowed, so use a sample with at least one element.

It changes the type of strings, numbers and booleans into a list, for example ["string","null"], so null values pass validation. It does not change objects or arrays, and a value that is already null in your sample gets the type null. If you want a nested object to be nullable too, you must edit it manually, for instance by using a type list on that object. This is useful when a field can be missing a value in practice.

By simple patterns on the sample value. Something like [email protected] gets format email, 2024-05-01 gets date, 2024-05-01T10:00:00Z gets date-time and a string starting with http:// or https:// gets uri. These are guesses made from one value, so a string that merely looks like an email will be marked as one. Check them, and delete any format that is wrong. Strict validators may reject values that do not match the format, so a wrong guess can break valid data.

No. A single sample gives no evidence for limits, allowed values or patterns, so the generator does not invent them. You add keywords like minimum, maxLength, enum and pattern yourself once you know the real rules. This is intended: a schema with made-up limits would reject valid data. Use the output as a structure, and add rules from your documentation or from the database column definitions that feed the JSON, then test them against real records.

No. Parsing and schema building happen locally in your browser tab, and there is no network call. Download saves a schema.json file on your device. Keep in mind that the examples option copies your values into the schema, so remove private data first or untick it. Other converters, such as JSON to XML and JSON to TOML, work in the same local way, and none of them keep a history.

Use a JSON Schema validator that supports your draft, such as Ajv in JavaScript or jsonschema in Python, and feed it both valid and invalid samples. This page does not validate data against the schema. Test that required fields are enforced, nulls are handled as you expect, and extra keys are rejected only if you turned that option on. Also confirm that an integer field rejects 1.5, since that is a common difference between the sample and real data.

Advertisement