JSON to JSON Schema
ConverterGenerate a JSON Schema (Draft-07) from sample JSON with properties, required fields and array items for runtime validation and API contract documentation.
{
"$schema": "http://json-schema.org/draft-07/schema#",
"type": "object",
"properties": {
"id": {
"type": "integer"
},
"name": {
"type": "string"
},
"active": {
"type": "boolean"
},
"tags": {
"type": "array",
"items": {
"type": "string"
}
},
"profile": {
"type": "object",
"properties": {
"age": {
"type": "integer"
},
"city": {
"type": "string"
}
},
"required": [
"age",
"city"
]
}
},
"required": [
"id",
"name",
"active",
"tags",
"profile"
]
}Related Tools
About JSON to JSON Schema
JSON Schema is the de-facto standard for describing and validating JSON structures, but writing one by hand is tedious and error-prone. This tool parses your sample JSON locally in the browser and infers a Draft-07 schema: each field's type, object properties and required lists, and array item types. All inference is local with nothing uploaded.
How to Use
- Open the JSON to JSON Schema tool
- Select the source and target formats
- Adjust the output options as needed
- Click the Convert button; results appear in real time
- Copy or export the result
Use Cases
- Validate API contracts — Generate a schema for request/response payloads to validate data at runtime and reject malformed input.
- Validate forms and config — Turn a config sample into a schema and validate user input or config files with libraries like ajv.
- Bootstrap OpenAPI — Get a schema quickly as the basis for components in OpenAPI/Swagger docs.
- Data quality gates — Use the schema as an entry check in data pipelines so downstream consumers get stable structures.
- Align team structures — Use the schema as a shared contract between frontend and backend to cut communication overhead.
- Generate UI forms — Derive a JSON Schema from a data sample to drive auto-generated form components with validation rules.
- Define database validation — Create a schema from a sample document to enforce shape constraints on JSON columns in PostgreSQL or MongoDB.
FAQ
Which schema version is produced?
It outputs JSON Schema Draft-07 by default, compatible with mainstream validators like ajv. Adjust to another draft after copying if needed.
Are all fields marked required?
Controlled by the "Mark required" toggle. When on, every field present in the sample is listed as required; for optional fields, turn it off and adjust manually.
How are mixed array types handled?
When array elements differ, the tool lists each possible sub-schema under anyOf to match the real data.
Are integers and floats distinguished?
Yes. Whole numbers infer to integer and decimals to number for more precise validation.
Can it validate my JSON?
This tool generates the schema. You can then validate real data with libraries like ajv or jsonschema, or an online validator.
The generated schema is too loose — how do I tighten it?
Because the tool only infers from your sample, a null in the sample widens the field to anyOf including null, and an empty object {} can only infer to {} which accepts anything — the leaner the sample, the looser the schema. To tighten it, edit the generated schema on the right: drop redundant null/type branches from anyOf, add properties and required to empty objects, and attach constraints like a pattern regex, minimum/maximum, or maxLength per business rules. Then validate with real samples to see which values still pass that shouldn't, and keep narrowing until only legitimate values are allowed.
How do I add enums and constraints like uniqueItems?
Edit the field's schema object directly in the editor on the right: add pattern or minLength for strings, minimum/maximum for numbers, an enum array for fixed value sets, and uniqueItems:true for arrays whose entries must not repeat. You can then copy the schema into a validator such as ajv and test it against a few real arrays to confirm the constraints behave as intended. More specific constraints catch more bad data at runtime, and the result doubles as an interface contract and collaboration doc that reduces type-mismatch rework during integration.