JSON to JSON Schema Generator
A tool that generates a starting JSON Schema (Draft 2020-12) from sample JSON such as API responses or config files. Nested objects and mixed-type arrays are supported, and constraints that can't be inferred from a sample, such as required and enum, are never added. The original sample is validated against the generated schema, which you can copy or save — all processed in your browser.
- Generates a starting point in JSON Schema Draft 2020-12. Only type, properties, and array items are output.
- A single sample can't tell which fields are required or which values are allowed, so constraints such as required, enum, format, and minimums, as well as additionalProperties, are not added. Add them as needed.
- All array items are combined into one schema. Mixed types become several types (or anyOf), and empty arrays have no items because the item type can't be determined.
Enter sample JSON to see the generated JSON Schema here.
How to use
- Paste sample JSON or load a file.
- A JSON Schema is generated on the right. Syntax errors show the line and column.
- The result of validating the original sample against the generated schema is shown.
- Use "Copy" or "Save" and add any constraints you need (required, enum, format, and so on).
About this tool
Writing a JSON Schema for validation from scratch takes time. This tool reads the types and structure of sample JSON and builds a starting schema. Whole numbers become integer and numbers with decimals become number.
A single sample can't tell which fields are required or which values are allowed, so required, enum, format, minimums, and additionalProperties are never added — only types and structure. All array items are merged into one schema, and properties that appear in different objects are combined.
The original sample is validated against the generated schema with the same engine as the JSON Schema Validator. Your JSON is never sent to a server.
For [1,2.5], the generated schema has type array and items with type number. The integer is covered by number rather than listed redundantly. For [1,"2"], items instead has a type array containing integer and string.
Passing the source sample does not mean the schema restricts future data sufficiently. An order quantity inferred as integer may still accept negative values. Add constraints such as minimum to match the actual rules, then validate both examples you want to accept and examples you want to reject.
Frequently asked questions
Why isn't required included?
A sample can't show whether a field is always present. Add the fields that must be present to required after generating.
How are empty arrays handled?
The item type is unknown, so only type: array is output without items. Empty objects likewise become just type: object.
What about arrays with mixed types?
Mixed primitive types are listed together in type. When objects or arrays are mixed with other types, anyOf is used.