JSON Schema Generator
Generate JSON Schema from JSON online for free. Paste or upload a JSON sample to infer nested objects, array items, field types, and required fields. Preview, copy, or download your schema without uploading your data.
{
"$schema": "https://json-schema.org/draft/2020-12/schema",
"type": "array",
"items": {
"type": "object",
"properties": {
"id": {
"type": "integer"
},
"name": {
"type": "string"
},
"email": {
"type": "string"
},
"profile": {
"type": "object",
"properties": {
"city": {
"type": "string"
},
"active": {
"type": "boolean"
}
},
"required": [
"city"
]
}
},
"required": [
"id",
"name",
"profile"
]
}
}What Is a JSON Schema Generator?
A JSON Schema generator creates a reusable description of data structure from example JSON. It identifies strings, numbers, objects, arrays and the fields in your sample. Use the result to document data or check other JSON with a compatible schema validator.
This tool converts JSON to JSON Schema in your browser. It infers likely rules from the example but cannot know every rule your application needs. Review the generated schema before using it with real data.
How to Convert JSON to JSON Schema Online
Paste or upload sample JSON
Use a JSON object or array, or select a .json file from your device.
Generate and review
Choose a schema draft and whether to infer required fields. Check nested objects, arrays, and mixed types.
Copy or download schema
Copy the result or save generated-schema.json, then adjust any rules your application requires.
JSON to JSON Schema Example
This example contains two objects with some shared fields. Because emailoccurs in just one object, it is optional in the generated item schema. Both id and name occur in both objects, so they are marked required.
[
{
"id": 1,
"name": "Ada",
"email": "ada@example.com",
"profile": {
"city": "London"
}
},
{
"id": 2,
"name": "Ben",
"profile": {
"city": "Paris",
"active": true
}
}
]{
"$schema": "https://json-schema.org/draft/2020-12/schema",
"type": "array",
"items": {
"type": "object",
"properties": {
"id": {
"type": "integer"
},
"name": {
"type": "string"
},
"email": {
"type": "string"
},
"profile": {
"type": "object",
"properties": {
"city": {
"type": "string"
},
"active": {
"type": "boolean"
}
},
"required": [
"city"
]
}
},
"required": [
"id",
"name",
"profile"
]
}
}How JSON Schema Types Are Inferred
The generator reads each example value and selects a JSON Schema type. Whole numbers use integer, while numbers with fractional values use number. When a field contains different kinds of values across examples, the schema allows each observed type instead of ignoring later examples.
| JSON sample | Inferred schema type | Meaning |
|---|---|---|
"Ada" | string | Text |
42 | integer | A whole number |
3.14 | number | A number with a fractional part |
1.0 | integer | JSON Schema considers this mathematically an integer |
true | boolean | True or false |
null | null | An explicit null value |
{"city":"London"} | object | Nested properties are inferred |
[1,2,3] | array with items | Elements have an inferred item type |
[1,"a",null] | Multiple types in items | Each observed element type is allowed |
Large integers and long decimals are analyzed without changing their precision. The schema describes the types of values it found rather than copying the original example values into the result. When an array contains both integers and fractional numbers, the common type becomes number.
Required vs Optional JSON Properties
required means a property must be present in an object. It does not mean that its value cannot be null. In the example below, id and nickname appear in both records, so they are required. email appears in only one record, so it remains an optional property.
[
{
"id": 1,
"nickname": null,
"email": "ada@example.com"
},
{
"id": 2,
"nickname": "Ben"
}
]{
"$schema": "https://json-schema.org/draft/2020-12/schema",
"type": "array",
"items": {
"type": "object",
"properties": {
"id": {
"type": "integer"
},
"nickname": {
"type": [
"string",
"null"
]
},
"email": {
"type": "string"
}
},
"required": [
"id",
"nickname"
]
}
}When does a field become required?
| Sample data | Result |
|---|---|
| Field appears in every object | Included in required when inference is enabled |
| Field is absent from at least one object | Described in properties, but not required |
Field is present with null | Presence still counts; its type can include null |
| Only one sample object | All present fields are marked required, with a reminder to review them |
| Required inference switched off | No automatically inferred required lists are generated |
The same rule is used inside nested objects and arrays of objects. With only one example, the generator cannot know which fields might be missing in real data. You can disable Mark fields as requiredand add the right constraints after reviewing the output.
Generate Schema for Nested JSON and Arrays
Nested objects become nested properties. For arrays, the generator examines all observed elements and combines their types and fields into an items schema. It does not simply use the first element. Different values for the same property may produce multiple allowed types.
Example: mixed numbers, null and an empty array
Here, score is an integer in one item, a decimal in another and null in a third. The generated schema permits both number and null. The empty tags array has no example items, so its element type cannot be inferred.
{
"items": [
{
"code": "A",
"score": 10
},
{
"code": "B",
"score": 9.5
},
{
"code": "C",
"score": null
}
],
"tags": []
}{
"$schema": "https://json-schema.org/draft/2020-12/schema",
"type": "object",
"properties": {
"items": {
"type": "array",
"items": {
"type": "object",
"properties": {
"code": {
"type": "string"
},
"score": {
"type": [
"number",
"null"
]
}
},
"required": [
"code",
"score"
]
}
},
"tags": {
"type": "array"
}
},
"required": [
"items",
"tags"
]
}Rules the tool will not guess
The tool intentionally does not guess enum values, email or date format, text patterns, minimums, maximums or string lengths. A sample with the value 42 does not prove that 42 is the largest allowed number. Add these constraints only when you know the application's actual rules.
If you turn on Reject extra object fields, object schemas include additionalProperties: false. This can reject valid future fields that were not present in the sample, so leave it off unless you need a strict structure.
JSON Schema Draft 2020-12 vs Draft-07
Choose Draft 2020-12 for the default output, or Draft-07 when a project depends on that older standard. The $schema field identifies which rules a validator should use. For this generator, both versions use the same supported core keywords: type, properties, items,required and additionalProperties.
| Schema version | Generated $schema value | When to choose it |
|---|---|---|
| Draft 2020-12 (default) | https://json-schema.org/draft/2020-12/schema | New projects and tools supporting Draft 2020-12 |
| Draft-07 | http://json-schema.org/draft-07/schema# | Existing applications that require Draft-07 |
Changing the version does not add extra rules. Check that the application or validator using your schema supports the version you select.
JSON Schema Generator vs JSON Validator
| Tool | Question it answers | Example |
|---|---|---|
| JSON Schema Generator | What structure does this sample suggest? | Create types and required fields from example JSON |
| JSON Validator | Is this JSON text syntactically valid? | Find a missing quote or extra comma |
| JSON Schema Validator | Does this JSON conform to a given schema? | Check that an id field is an integer |
To check syntax, use our JSON Validator. To inspect an example more easily, use the JSON Formatter. This page generates schemas; it does not validate other documents against them.
Common JSON Schema Generation Problems
| What you see | What to do |
|---|---|
| Every field is marked required | If you used only one object, add examples where optional fields are missing, or turn off Mark fields as required. |
Empty arrays have no items rule | Include example elements when you need an inferred item type. |
| A field allows several types | Check the input examples; the union represents the types actually observed. |
null appears in a property type | A sample contains an explicit null; this is different from a missing field. |
| The schema rejects an unexpected field | Turn off Reject extra object fields unless you want to block fields not shown in your sample. |
| Dates or emails appear as strings | The tool does not guess string formats; add format manually where appropriate. |
| JSON input cannot be parsed | Check brackets, quotes and commas, or use the JSON Validator for syntax checking. |
| Input is too large or deeply nested | Use a smaller representative sample: the input limit is 10 MiB, and nesting is limited to 64 levels below the root. |
Generated schemas can be copied or downloaded as generated-schema.json. The on-screen preview shows at most 8,000 characters, but the full result is available for copy or download. Generation also has browser limits for very large samples and output files.
Need TypeScript declarations for the same JSON? Generate TypeScript interfaces or types. TypeScript types are used during development; this tool creates JSON Schema.
Frequently asked questions
What is a JSON Schema generator?
A JSON Schema generator uses example JSON to describe the fields and data types your documents contain. Use the result to document your data or with a compatible validator to check other JSON files.
How do I generate JSON Schema from JSON online?
Paste JSON or choose a .json file, select a schema version, and click Generate JSON Schema. Review the result, then copy it or download generated-schema.json.
Is this JSON Schema generator free?
Yes. You can use it for free without creating an account. Your input is processed in your browser.
Does it support nested JSON objects and arrays?
Yes. Nested objects get rules for their fields, and arrays get rules for their elements. If an array contains objects, the generator looks at all of them, not just the first.
How are required and optional fields detected?
With Mark fields as required enabled, a field is required when it appears in every relevant example object. If you provide only one object, check whether any of its fields should actually be optional.
Are null values treated as optional fields?
No. A field with a null value is still present. Whether it is required depends on whether the field appears in every relevant example, not on whether its value is null.
What happens with empty arrays or objects?
An empty array gives no clue about what its elements should contain, so the generator leaves that rule open. An empty object has no fields to describe. Add examples with values to get a more specific schema.
Does it support JSON Schema Draft 2020-12 and Draft-07?
Yes. Draft 2020-12 is the default. Choose Draft-07 if you need that version for an existing tool or application.
Can I make the schema reject extra object properties?
Yes. Turn on Reject extra object fields to add additionalProperties: false to object schemas. Leave it off if your JSON may contain fields missing from the examples.
Does the generator detect email formats, enums or number limits?
No. The tool does not guess email or date formats, lists of allowed values, number ranges, or text lengths from a sample. Add those rules only when you know the actual requirements.
Can I download the generated JSON Schema?
Yes. Copy the complete schema or download a .json file named generated-schema.json. The preview may be shortened for display, but the download contains the full result.
Is my JSON uploaded to a server?
No. JSON input, schema generation and downloads run locally in your browser. The JSON contents and generated schema are not sent to a conversion server.
Can I validate JSON against the generated schema here?
This page generates a schema from sample data; it does not check other JSON documents against that schema. Our JSON Validator checks JSON syntax, which is a different kind of validation.
Will the generated schema work for all future JSON data?
Not necessarily. The generated schema describes only the examples you provide. Review required fields, allowed types and extra-field settings before using it to check other important data.