Generate JSON Schema (draft-07) from sample JSON data. Detects string formats (email, URI, UUID, date-time), merges schemas from multiple samples, and outputs a clean schema ready for validation. Zero dependencies.
Like quicktype but needs no installation — and genson (Python) or online tools are overkill when you just need a schema.
npm install -g json-schema-genOr without installing:
npx json-schema-gen data.jsonGiven user.json:
{
"id": "a1b2c3d4-e5f6-7890-abcd-ef1234567890",
"name": "Alice Johnson",
"email": "alice@example.com",
"age": 32,
"active": true,
"createdAt": "2024-01-15T09:30:00Z",
"tags": ["admin", "user"],
"address": {
"street": "123 Main St",
"city": "Springfield",
"zip": "62701"
}
}Running json-schema-gen user.json --required outputs:
{
"$schema": "https://json-schema.org/draft-07/schema",
"type": "object",
"properties": {
"id": { "type": "string", "format": "uuid" },
"name": { "type": "string" },
"email": { "type": "string", "format": "email" },
"age": { "type": "integer" },
"active": { "type": "boolean" },
"createdAt": { "type": "string", "format": "date-time" },
"tags": { "type": "array", "items": { "type": "string" } },
"address": {
"type": "object",
"properties": {
"street": { "type": "string" },
"city": { "type": "string" },
"zip": { "type": "string" }
},
"required": ["street", "city", "zip"],
"additionalProperties": false
}
},
"required": ["id", "name", "email", "age", "active", "createdAt", "tags", "address"],
"additionalProperties": false
}json-schema-gen user.json # Basic schema
json-schema-gen user.json --required # Mark all fields as required
json-schema-gen user.json --title "User" --id "/schemas/user"
json-schema-gen user.json --out schema.json # Write to file
json-schema-gen s1.json s2.json s3.json # Merge from multiple samples
cat data.json | json-schema-gen - # Read from stdin| Format | Example |
|---|---|
date-time |
"2024-01-15T09:30:00Z" |
date |
"2024-01-15" |
time |
"09:30:00" |
email |
"user@example.com" |
uri |
"https://example.com" |
uuid |
"a1b2c3d4-e5f6-7890-abcd-ef1234567890" |
ipv4 |
"192.168.1.1" |
Pass multiple JSON files to infer a schema that covers all of them. Fields present in only some samples will not be marked required:
json-schema-gen user1.json user2.json user3.json| Flag | Description |
|---|---|
--required |
Mark all non-null fields as required |
--examples |
Include example values for string fields |
--title <name> |
Add title to the schema |
--id <uri> |
Add $id to the schema |
--out <file> |
Write output to a file |
MIT
json schema generator · json to schema · quicktype alternative · genson alternative · infer schema · draft-07 · generate schema · json schema · zero dependencies · cli
Built to solve, shared to help — Rushabh Shah 🛠️✨
One of 40+ zero-dependency developer CLI tools — no node_modules, ever.