@lowdep/json-schema-gen
v1.0.0
Published
Generate JSON Schema (draft-07) from sample JSON data — format detection, multi-sample merging, zero dependencies
Maintainers
Readme
json-schema-gen
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.
Install
npm install -g json-schema-genOr without installing:
npx json-schema-gen data.jsonExample
Given user.json:
{
"id": "a1b2c3d4-e5f6-7890-abcd-ef1234567890",
"name": "Alice Johnson",
"email": "[email protected]",
"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
}Usage
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 stdinDetected Formats
| Format | Example |
|---|---|
| date-time | "2024-01-15T09:30:00Z" |
| date | "2024-01-15" |
| time | "09:30:00" |
| email | "[email protected]" |
| uri | "https://example.com" |
| uuid | "a1b2c3d4-e5f6-7890-abcd-ef1234567890" |
| ipv4 | "192.168.1.1" |
Multi-Sample Merging
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.jsonOptions
| 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 |
License
MIT
Keywords
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.
