JSON Schema Generator
Paste one or more JSON examples and get a JSON Schema, the same schema wrapped for OpenAI Structured Outputs or a Claude tool, and matching TypeScript, Zod and Pydantic code.
Last checked
Sample JSON
Schema
Paste a JSON example or try the sample. The schema appears here in the format you pick above.
How to use it
- Paste a JSON example of the answer you want from the model. A top-level array can be read as a list of samples, which gives better optional fields and enums.
- Pick Standard for a normal schema or Strict for OpenAI Structured Outputs, give the schema a name, and turn on enum detection if a field holds a fixed set of values.
- Open Property descriptions and say what each field means; models read these descriptions.
- Switch the output to JSON Schema, OpenAI text.format, Claude output_config, Claude tool, TypeScript, Zod or Pydantic, read the warnings, and copy or download the result.
- Paste a real answer into Validate JSON against this schema to see whether it fits.
What it checks and why
Structured outputs and function calling both take a JSON Schema: the model is told, or forced, to answer in that shape. Writing the schema by hand for a nested answer is slow and easy to get wrong, while an example of the answer is usually already at hand. The generator reads the example and writes the schema for it.
OpenAI's strict mode has its own rules, set out in the Supported schemas section of its Structured Outputs guide: the root must be an object, every field must be listed in required, every object needs additionalProperties set to false, and optional fields are written as a union with null. A schema may have up to 5000 object properties in total and up to 10 levels of nesting. Strict mode here follows those rules and warns when a sample breaks them.
Claude takes a schema in two places. For JSON outputs, the request carries it in output_config.format with type json_schema, and the answer comes back as JSON in the text block. For tools, it is the input_schema of a tool definition, and strict: true on the tool makes Claude's tool inputs follow the schema exactly. Both need additionalProperties false on every object, so use Strict mode for them. The tool output leaves a description for you to write, because Anthropic's guide says a detailed description matters more than anything else in a tool definition.
Enums come from repetition. With detection on, a string field becomes an enum when its values repeat across the samples (or across the items of an array) and there are no more distinct values than the limit you set. A field seen only once never becomes an enum, because one value says nothing about the allowed set. A nullable enum lists null as well, so null still passes validation.
The code outputs are written from the schema, as plain text with no library in the page. TypeScript gets one interface per object; Zod sticks to the basic calls (z.object, z.string, z.enum, z.array, z.union, .nullable, .optional, .describe) so it reads the same in Zod 3 and 4; Pydantic gets BaseModel classes with Field descriptions, aliases for keys that are not valid Python names, and extra="forbid" in strict mode.
Specs and sources
Limits
- A schema learned from examples only knows what the examples show. Minimum and maximum values and string patterns have to be added by hand, and enum detection can only list values that appear in the samples.
- Formats stay in the JSON Schema only: TypeScript, Zod and Pydantic type a date-time or email as a plain string.
- An empty array gives no item type, so its items are typed as string with a warning. Put at least one item in the sample.
- Formats are guessed from the text of the value, so a string that only looks like a date gets a date format. Turn detection off if that is wrong.
- The validator checks only the keywords this tool writes. Hand-written keywords such as minimum, pattern or $ref are ignored there.
Questions
- How do I generate a JSON Schema from JSON?
- Paste the JSON above and the schema appears at once. Each value becomes a type, each object lists its properties, and arrays get an items schema built from all their elements.
- Why does OpenAI say all fields must be required?
- Strict mode needs every key in required so the model always produces the full shape. To make a field optional, give it a union type with null, which is what strict mode here does for keys missing from some samples.
- What is additionalProperties false?
- It forbids keys that the schema does not list. OpenAI requires it on every object in strict mode, and it is a good default for any schema that checks model output.
- Can I use the same schema for Claude and OpenAI?
- Mostly yes. Both take standard JSON Schema with additionalProperties false on every object. OpenAI reads it as the schema of text.format; Claude reads it in output_config.format for JSON outputs or as a tool's input_schema with strict: true. Claude also accepts the uri format, which OpenAI strict mode does not, so a schema from Strict mode here works in both.
- How do I validate JSON against a JSON Schema?
- Generate or paste the schema's sample above, then paste the JSON into Validate JSON against this schema. Each problem is listed with its JSON Pointer path, such as /items/0/price. The validator covers what this tool writes: types, required keys, extra keys, items, enums, unions and formats.
- How do I convert JSON to a Zod schema or a Pydantic model?
- Paste the JSON, then switch the output to Zod or Pydantic v2. Both are built from the same schema, so optional keys, nullable fields, enums and descriptions match the JSON Schema output.
- How do I add descriptions to a JSON Schema?
- Open Property descriptions under the options and type a description next to each field. It is written as the description keyword in the schema, a JSDoc comment in TypeScript, .describe() in Zod and Field(description=...) in Pydantic.
- Is my JSON uploaded anywhere?
- No. The schema is built in your browser with JSON.parse and plain TypeScript, so sample data, including real customer records, stays on your device.