How to use the json to json schema converter
- Paste your JSON sample into the text area.
- Toggle options: mark all properties required, include the
$schemakeyword or forbid additional properties. - The inferred JSON Schema appears instantly below the input.
- Copy the result and use it for validation or documentation.
How json to json schema inference works
This json to json schema converter walks the parsed JSON tree recursively. Each value maps to a JSON Schema type: strings become "string", booleans become "boolean", null becomes "null". Numbers are split into "integer" when they have no fractional part and "number" otherwise.
For objects, every key becomes a property. A key is marked required only if it appears in every object at that level across the entire sample. When you enable the all-required option, every discovered key is added to the required array regardless of presence.
Arrays merge the schemas of all their elements. If an array contains both integers and strings, the items schema uses a type union like ["integer", "string"]. Nested objects inside arrays are merged so that properties found in any element are included.
Draft 2020-12 features used
The output targets the JSON Schema draft 2020-12 specification. Nullable values are expressed by adding "null" to the type array rather than using the deprecated nullable keyword from older drafts.
The optional $schema keyword points to https://json-schema.org/draft/2020-12/schema, telling validators which dialect to apply. Setting additionalProperties to false produces a closed schema that rejects any keys not explicitly defined in the properties map.
Worked example
Consider this input:
{"name": "Ada", "scores": [98, null]}
The root is an object with two keys present, so both are required. The name property infers {"type": "string"}. The scores array contains an integer and a null, so its items schema merges them into {"type": ["integer", "null"]}. The final output lists properties alphabetically and places the required array after them.
Limitations of single-sample inference
A schema generated from one JSON document is an educated guess, not an authoritative contract. The tool cannot know whether a string should be constrained to a specific format like email or date-time, nor can it determine minimum or maximum numeric bounds. Optional fields that happen to be present in your sample will appear as required unless you disable that behaviour.
For production APIs, review the output and add constraints manually. If you need to convert JSON to other formats, tools like JSON to XML or JSON to Go struct handle those transformations directly.
Common mistakes to avoid
Trailing commas and single quotes are not valid JSON and will cause a parse error. Use double quotes for all keys and string values. Very large files may take a moment to process because the entire tree must be traversed synchronously.
When merging arrays of mixed objects, properties unique to one element are still included in the merged schema but are not marked required. This prevents validation failures on documents where some elements omit optional fields.
Worked examples
| Example | Input | Result |
|---|---|---|
| Simple object | JSON input: {"name": "Ada", "age": 36, "active": true}; Mark all properties as required: no; Add $schema keyword: yes; Set additionalProperties to false: no | { / "$schema": "https://json-schema.org/draft/2020-12/schema", / "type": "object", / "properties": { / "active": { / "type": "boolean" / }, / "age": { / "type": "integer" / }, / "name": { / "type": "string" / } / }, / "required": [ / "active", / "age", / "name" / ] / } |
| Array of objects | JSON input: [{"id": 1, "tag": "a"}, {"id": 2}]; Mark all properties as required: no; Add $schema keyword: yes; Set additionalProperties to false: no | { / "$schema": "https://json-schema.org/draft/2020-12/schema", / "type": "array", / "items": { / "type": "object", / "properties": { / "id": { / "type": "integer" / }, / "tag": { / "type": "string" / } / }, / "required": [ / "id" / ] / } / } |
| Nullable field | JSON input: {"value": null, "label": "test"}; Mark all properties as required: no; Add $schema keyword: yes; Set additionalProperties to false: no | { / "$schema": "https://json-schema.org/draft/2020-12/schema", / "type": "object", / "properties": { / "label": { / "type": "string" / }, / "value": { / "type": "null" / } / }, / "required": [ / "label", / "value" / ] / } |
FAQ
What JSON Schema version does this produce?
It generates schemas conforming to draft 2020-12, the current standard. You can optionally include the $schema keyword pointing to the official meta-schema URI.
Is my data sent to a server?
No. Parsing and inference run entirely in your browser using JavaScript. Nothing leaves your device.
Why are some properties marked required when they should be optional?
The tool marks a property required if it appears in every object instance at that path in your sample. Provide multiple examples in an array or uncheck the all-required option to adjust this.
How are null values handled?
A standalone null produces a schema with type null. When null appears alongside other types in an array, it is added to the type array, creating a nullable union.
Can I use the output for API validation?
Yes, but review it first. Inferred schemas lack constraints like string patterns, number ranges and enum values that you may need for strict validation.
Does it handle deeply nested structures?
Yes. The recursive algorithm processes objects and arrays to any depth supported by your browser's call stack.