Skip to content
FreeAIDevTools

JSON to JSON Schema

Updated

How do you convert JSON to JSON Schema? Paste a sample JSON object below and the generator writes a draft 2020-12 JSON Schema: types for every field, nested objects, one merged item schema per array, and null where your sample had it. Switch on OpenAI strict mode to add additionalProperties: false and a full required list to every object. It all runs in your browser.

Output:
Paste a sample of the JSON you expect, or load the example. The schema appears here as you type.

The Inference Report · Every Tuesday

Know when AI prices change.

One short email every Tuesday: new models, price moves and free tiers that were cut or added. Five minutes, no fluff.

No spam. Unsubscribe anytime.

What does a JSON to JSON Schema generator do?

It reads a sample of your data and writes the schema that describes it: the type of every field, the shape of each nested object, and one item schema for every array. You paste a real API response or a hand-written example and get a draft 2020-12 JSON Schema to edit, instead of writing one from a blank file.

Here is how we read a sample:

  • Types. Each value becomes string, integer, number, boolean, null, object or array. A field with only whole numbers is integer. A field with both 2 and 2.5 is number.
  • Arrays. We merge every element into one item schema, so a key that appears in only some elements still shows up. In the plain schema, a key that is in every element is required and the rest are optional.
  • Null. If a field is null anywhere in the sample, its type gets "null" added, as in ["string", "null"]. If it is null everywhere, null is all we can say, and we flag it.
  • Mixed types. A field that holds both strings and numbers gets a type list. When objects or arrays are part of the mix, we use anyOf with one branch per type.

A schema built from one sample only knows what that sample shows. We don't guess formats such as email or date-time, enums, or length limits, so add those by hand where they matter. If your sample won't parse, the JSON formatter and validator shows the line and column of the error.

How does OpenAI strict mode change the schema?

Strict mode makes the schema follow the rules in OpenAI's Structured Outputs guide, so the API accepts it with "strict": true. Every object gets "additionalProperties": false, every property goes into required, and a field that can be missing becomes nullable, because strict mode has no optional fields.

OpenAI strict mode rules and what the tool does
OpenAI ruleWhat the tool does
The root must be an object and must not use anyOfWraps an array root in {"items": ...} and any other value in {"value": ...}, and tells you
additionalProperties: false on every objectAdds it to every object, including nested objects and array items
All fields must be requiredLists every key in required, in the same order as properties
Emulate an optional field with a union with nullKeys that were missing or null become ["type", "null"]; objects and arrays get anyOf with a {"type": "null"} branch
Up to 5,000 object properties and 10 levels of nestingWarns when your schema goes over either limit
Names, enum and const values total at most 120,000 characters; at most 1,000 enum valuesChecked too, mostly useful when you fix a schema that already has enums
allOf, not, dependentRequired, dependentSchemas, if, then and else are not supportedFlags them with their location, so you choose how to rewrite them

Source: the Supported schemas section of OpenAI's Structured Outputs guide, checked 16 November 2026. The guide also says outputs come back in the key order of the schema, so we keep your keys in the order they first appear. For nullable objects we use anyOf with a null branch, the pattern OpenAI's own recursive example uses, and we leave out the $schema keyword because it is not on OpenAI's list.

Worked example: from an order sample to a strict schema

Take an order with two line items. The first item has a null gift note. The second has a real gift note and a discount that the first item doesn't have. This is the sample behind the Load example button.

{
  "order_id": "A-1042",
  "customer": { "name": "Ada Lovelace", "email": "[email protected]" },
  "items": [
    { "sku": "KB-01", "qty": 1, "price": 49.5, "gift_note": null },
    {
      "sku": "MS-02",
      "qty": 2,
      "price": 19,
      "gift_note": "Happy birthday",
      "discount": 0.1
    }
  ],
  "paid": true
}

In the plain schema, the item schema merges both items. Price is number because 49.5 and 19 appear together, gift_note is ["string", "null"] because one sample was null, and discount is left out of required because only one item has it:

{
  "type": "object",
  "properties": {
    "sku": { "type": "string" },
    "qty": { "type": "integer" },
    "price": { "type": "number" },
    "gift_note": { "type": ["string", "null"] },
    "discount": { "type": "number" }
  },
  "required": ["sku", "qty", "price", "gift_note"]
}

Switch on OpenAI strict mode and the same item schema changes in three places. Discount moves into required and becomes ["number", "null"], so the model sends "discount": null for items without one. The object gets "additionalProperties": false. The customer object and the root get the same treatment, for 11 properties in 3 objects.

{
  "type": "object",
  "properties": {
    "sku": { "type": "string" },
    "qty": { "type": "integer" },
    "price": { "type": "number" },
    "gift_note": { "type": ["string", "null"] },
    "discount": { "type": ["number", "null"] }
  },
  "required": ["sku", "qty", "price", "gift_note", "discount"],
  "additionalProperties": false
}

To send it, pick a wrapper. For Chat Completions the schema goes in response_format: {"type": "json_schema", "json_schema": {"name", "strict": true, "schema"}}. For the Responses API it goes in text.format with name, strict and schema at the same level. The name may use a to z, A to Z, 0 to 9, underscores and dashes, up to 64 characters, per the Chat Completions and Responses API reference.

What does "Invalid schema for response_format" mean?

OpenAI refused the request because you sent a schema with "strict": true and it breaks one of the Structured Outputs rules in the table above. The text after the colon names the rule and the spot in your schema. In one report on OpenAI's developer forum, it came back as an HTTP 400 invalid_request_error with param set to response_format and the message In context=('properties', 'category'), schema must have a 'type' key., caused by an enum defined without any values.

Two variants have their own answer below: a missing "additionalProperties": false and a required list that leaves out a key. Make a schema strict fixes both in one pass. For any other variant, find the rule the message names in the table above. The tool flags unsupported keywords such as allOf and if/then/else with their location, and warns when a schema goes over OpenAI's size limits.

How do I fix "additionalProperties is required to be supplied and to be false"?

That error means strict mode is on and at least one object in your schema lacks "additionalProperties": false. The message names the spot, for example In context=('properties', 'v1_approach') in a report on OpenAI's developer forum. Nested objects and entries under $defs are the easy ones to miss.

Its sibling, 'required' is required to be supplied and to be an array including every key in properties, means a required list is missing a key, or names one that is not in properties (the forum thread on an extra required key shows the second case). Both have the same fix. Switch the tool to Make a schema strict and paste your schema, your whole response_format, or a function tool definition. We then:

  1. add "additionalProperties": false to every object, including $defs and anyOf branches;
  2. set required to every key in properties and drop keys that are not there;
  3. make each key that was optional nullable, so your code still sees null where the field used to be absent;
  4. set "strict": true on the wrapper, if you pasted one, and list every change.

Some things we flag instead of rewriting. allOf, not and if/then/else need a human decision. An object with no fixed keys, such as a map whose additionalProperties is a schema, can only be an empty object once additionalProperties is false, so list the keys you expect or use an array of key and value pairs.

Do long property names cost more?

A little, on every call. The model writes each key in each response, and that text is billed as output tokens like any other. Paste a typical response into the token counter to see its size, then price a month of calls in the LLM cost calculator. Strict mode fixes the shape of the answer, not its content, so say what each field should hold in a description or in your instructions. The system prompt builder has an output format section for that.

Frequently asked

How do I fix "additionalProperties is required to be supplied and to be false"?

OpenAI returns that error when strict mode is on and an object in your schema, often a nested one or one inside $defs, does not have "additionalProperties": false. Switch the tool to Make a schema strict and paste the schema or the whole response_format. We add the flag to every object, list every property in required, and show each change we made.

How do I make a field optional in OpenAI strict mode?

You can't leave it out of required, because OpenAI's Structured Outputs guide says every field must be required. Make it nullable instead, for example "type": ["string", "null"]. The model then always returns the key and sends null when it has no value. Our strict mode does this for every key that was missing from some of your samples.

Which JSON Schema features does OpenAI strict mode support?

As of 16 November 2026, OpenAI's guide lists string, number, boolean, integer, object, array, enum and anyOf, plus $defs and recursive $ref. Strings can use pattern and format, numbers minimum, maximum, the exclusive bounds and multipleOf, and arrays minItems and maxItems. allOf, not, dependentRequired, dependentSchemas, if, then and else are not supported. A schema can have up to 5,000 object properties and 10 levels of nesting.

Why is a field typed as integer when it can hold decimals?

JSON does not keep the difference between 1 and 1.0: JSON.parse reads both as the number 1, so a sample with only whole numbers gives "type": "integer". If the field can hold decimals, put one decimal value in your sample or change the type to number by hand. When a field has both kinds in the sample, we use number.

Is my JSON sent anywhere?

No. The schema is built in your browser with JSON.parse and plain JavaScript, with no network request and no analytics on what you paste, so it is safe for real API responses. If your sample won't parse, the JSON formatter and validator shows the line and column of the error.