Registry / devops / generate-schema

generate-schema

JSON →
library2.6.0jsnpmunverified

Convert JSON objects to MySQL Table Schema, JSON Schema, Mongoose Schema, ClickHouse Schema, Google BigQuery, or a Generic template. Version 2.6.0 is the latest stable release, with infrequent updates. Key differentiator: supports multiple output formats (MySQL, ClickHouse, BigQuery) from a single JSON input, with both CLI and programmatic API. Alternatives like json-schema-generator only output JSON Schema.

npm install generate-schema
INSTALL
IMPORT
SIG · GENERATE-SCHEMA
G
generate-schema
devopsjavascriptv2.6.0
harness data pending
Install & Compatibility
Where this runs

No compatibility data collected yet for this library.

Code
Verified usage

Verified import paths — ran on the pinned version, not inferred.

GenerateSchema
const GenerateSchema = require('generate-schema');
import GenerateSchema from 'generate-schema';
Package uses CommonJS; no default ESM export.
generate-schema CLI
npx generate-schema --json-schema data.json
generate-schema --json data.json
CLI flag is --json-schema or -j, not --json.
GenerateSchema.json
GenerateSchema.json('MySchema', myObject);
GenerateSchema.json(myObject);
First argument is title (optional), second is data.

Converts an array of JSON objects to JSON Schema using GenerateSchema.json method.

const GenerateSchema = require('generate-schema'); const product = [ { id: 2, name: 'An ice sculpture', price: 12.50, tags: ['cold', 'ice'] }, { id: 3, name: 'A blue mouse', price: 25.50 } ]; const schema = GenerateSchema.json('Product', product); console.log(JSON.stringify(schema, null, 2));
Debug
Known issues
gotchaThe json method expects title as first argument; omitting it may cause unexpected schema output.
fix
Always pass a string title as first argument: GenerateSchema.json('Title', data);
affects: >=2.0.0
gotchaThe mysql and clickhouse methods require a table name as first argument; passing an object directly will fail.
fix
Use GenerateSchema.mysql('my_table', data); or GenerateSchema.clickhouse('my_table', data, 'date');
affects: >=2.0.0
deprecatedThe CLI option --help does not show all options; check the README for full list.
fix
Use --help or -h for basic options; refer to documentation for detailed flags.
affects: >=2.5.0
gotchaJSON Schema output uses draft-04 (not draft-07 or 2020-12) which may lack modern features.
fix
If you need newer draft, consider alternative libraries like jsonschema.
affects: >=2.0.0
Errors
Common errors & fixes
TypeError: GenerateSchema.json is not a function
Using ES module import syntax with a CommonJS package.
fix
Use 'const GenerateSchema = require("generate-schema")' instead of 'import GenerateSchema from "generate-schema"'.
error: unknown option '--json'
The CLI uses -j / --json-schema, not --json.
fix
Use 'generate-schema -j data.json' or 'generate-schema --json-schema data.json'.
Cannot read property '0' of undefined
Passed an empty array or null to GenerateSchema.json without a title.
fix
Provide a title as first argument and ensure data is non-empty: GenerateSchema.json('Title', [{...}]).
Upgrade
Version history
2.6.0latest on npm
Audit
Dependencies
commanderrequiredCLI argument parsing
Agent activity
6 hits · last 30 days
node
4
Resources
generate-schema — npm install generate-schema · libregistry