How to Convert JSON to JSON Schema
Converting sample JSON data into a formal JSON Schema allows you to quickly generate contracts for API endpoints, payload validation, and data pipelines without writing schemas by hand.
- Input JSON Example: Paste a valid JSON object or array into the input editor pane.
- Select Schema Specification: Choose Draft-07 (industry standard), Draft-04 (legacy), or 2020-12 (latest specification).
- Configure Inference Constraints: Toggle Infer Required Properties to mandate present fields, or toggle Allow Additional Properties to accept open payloads.
- Inspect & Copy: The inference engine analyzes tokens recursively and outputs clean JSON Schema on the right. Click Copy or Download.
How JSON Schema Types Are Inferred
The schema converter inspects each value to map it to JSON Schema specification types:
- Strings: Text values enclosed in quotes are assigned
"type": "string". - Integers vs Numbers: Whole numeric values without decimal fractions are given
"type": "integer", while floating-point numbers receive"type": "number". - Booleans:
trueandfalseprimitives map to"type": "boolean". - Nulls: Nullable attributes map to
"type": "null"or multi-type unions like["string", "null"].
Nested Objects and Arrays
Real-world JSON data rarely consists of flat key-value pairs. The inference engine recursively traverses nested object hierarchies and array elements:
- Nested Objects: Child objects generate nested
propertiesdictionaries with their own local required constraints. - Homogeneous Arrays: Arrays where every element shares the same structure (e.g. lists of user objects) produce a unified
itemsschema. - Polymorphic / Mixed Arrays: Arrays with varied data types are inferred using the standard
anyOfcombinator keyword.
Required vs Optional Properties
In JSON Schema, properties are optional by default unless declared inside the object's required array. When Infer Required Properties is enabled, every property present in your sample object is declared as mandatory. If you are building a schema for a flexible payload with optional attributes, you can uncheck this option or use our Visual JSON Schema Builder to manually configure required toggles per property.
JSON to JSON Schema Example
Here is a practical demonstration of how sample JSON data translates into an inferred Draft-07 schema:
{
"name": "John",
"age": 30
}
{
"$schema": "http://json-schema.org/draft-07/schema#",
"type": "object",
"properties": {
"name": {
"type": "string"
},
"age": {
"type": "integer"
}
},
"required": [
"name",
"age"
]
}
Need to build a schema manually or set custom constraints like regex patterns, enums, and min/max numbers? Try the Visual JSON Schema Builder, validate payloads with JSON Schema Validator, or format raw JSON with JSON Formatter.