
Product
Introducing Socket MCP for Claude Desktop
Add secure dependency scanning to Claude Desktop with Socket MCP, a one-click extension that keeps your coding conversations safe from malicious packages.
generate-schema
Advanced tools
Effortlessly convert your JSON Object to JSON Schema, Mongoose Schema, or a Generic template for quick documentation / upstart.
The generate-schema npm package is a tool that allows users to generate JSON schemas from JSON data. It is useful for creating schemas that can validate JSON data structures, ensuring that data conforms to expected formats.
Generate JSON Schema from JSON Object
This feature allows you to generate a JSON schema from a given JSON object. The code sample demonstrates how to use the generate-schema package to create a schema from a simple JSON object containing personal information.
const generateSchema = require('generate-schema');
const myData = {
name: "John Doe",
age: 30,
email: "john.doe@example.com"
};
const schema = generateSchema.json(myData);
console.log(JSON.stringify(schema, null, 2));
Generate JSON Schema from JSON Array
This feature allows you to generate a JSON schema from a JSON array. The code sample shows how to create a schema from an array of objects, each representing a person with a name and age.
const generateSchema = require('generate-schema');
const myDataArray = [
{ name: "John Doe", age: 30 },
{ name: "Jane Doe", age: 25 }
];
const schema = generateSchema.json(myDataArray);
console.log(JSON.stringify(schema, null, 2));
The jsonschema package is a validator for JSON schemas. It allows you to validate JSON data against a schema to ensure it meets the required structure. Unlike generate-schema, which focuses on generating schemas, jsonschema is primarily used for validation purposes.
AJV (Another JSON Validator) is a fast JSON schema validator. It supports JSON Schema draft-07 and is used to validate data against JSON schemas. While generate-schema is used to create schemas, AJV is used to validate data against those schemas, offering high performance and additional features like custom keywords.
The jsontoxml package is used to convert JSON data to XML format. While it does not generate JSON schemas, it provides a way to transform JSON data into another format, which can be useful in different contexts. It serves a different purpose compared to generate-schema, focusing on data transformation rather than schema generation.
Convert JSON Objects to MySQL Table Schema, JSON Schema, Mongoose Schema, ClickHouse Schema, Google BigQuery, or a Generic template for documentation, code generation, and more.
Install with npm:
$ npm i --save generate-schema
Optionally, add -g
to the above if you want the generate-schema
command line executable.
Usage: generate-schema [options ...] [file]
Common Options:
-h, --help output usage information
-V, --version output the version number
-q, --quiet Skip help message in program output
Mode Options:
-g, --generic Generic JSON Primitives schema output
-j, --json-schema JSON Schema output
-s, --mysql MySQL Table Schema output
-m, --mongoose Mongoose Schema output
-b, --big-query Google BigQuery Schema output
-c, --clickhouse Clickhouse Table Schema output
When no file is specified, generate-schema
enters a REPL mode.
$ generate-schema -b
generate-schema v2.5.1 (bigquery)
Type "exit" to quit.
Type {a:"b"} to see an example.
> {a:"b"}
[
{
"name": "a",
"type": "STRING",
"mode": "NULLABLE"
}
]
var GenerateSchema = require('generate-schema')
// Capture Schema Output
var schema = GenerateSchema.json('Product', [
{
"id": 2,
"name": "An ice sculpture",
"price": 12.50,
"tags": ["cold", "ice"],
"dimensions": {
"length": 7.0,
"width": 12.0,
"height": 9.5
},
"warehouseLocation": {
"latitude": -78.75,
"longitude": 20.4
}
},
{
"id": 3,
"name": "A blue mouse",
"price": 25.50,
"dimensions": {
"length": 3.1,
"width": 1.0,
"height": 1.0
},
"warehouseLocation": {
"latitude": 54.4,
"longitude": -32.7
}
}
])
Outputs:
{
"$schema": "http://json-schema.org/draft-04/schema#",
"title": "Product Set",
"type": "array",
"items": {
"type": "object",
"properties": {
"id": {
"type": "number"
},
"name": {
"type": "string"
},
"price": {
"type": "number"
},
"tags": {
"type": "array",
"items": {
"type": "string"
}
},
"dimensions": {
"type": "object",
"properties": {
"length": {
"type": "number"
},
"width": {
"type": "number"
},
"height": {
"type": "number"
}
}
},
"warehouseLocation": {
"type": "object",
"properties": {
"latitude": {
"type": "number"
},
"longitude": {
"type": "number"
}
}
}
},
"required": [
"id",
"name",
"price",
"dimensions",
"warehouseLocation"
],
"title": "Product"
}
}
g.generic(Object object)
Generates a generic schema from object
. Property types are described using primitives.
g.mysql([String tableName,] Mixed object)
Generates MySQL Table Schema from object
.
tableName
is optional, defaults to generic
object
must be of type Object
or Array
g.json([String title,] Mixed object)
Generates JSON Schema from object
.
title
is optionalobject
must be of type Object
or Array
g.mongoose(Object object)
Generates a Mongoose Schema from object
.
g.bigquery(Object object)
Generates a Google BigQuery schema from object
.
g.clickhouse([String tableName,] Mixed object, String dateField)
Generates ClickHouse Table Schema from object
.
tableName
is optional, defaults to generic
object
must be of type Object
or Array
dateField
Date field for ENGINE, must be of type Date
FAQs
Effortlessly convert your JSON Object to JSON Schema, Mongoose Schema, or a Generic template for quick documentation / upstart.
The npm package generate-schema receives a total of 139,575 weekly downloads. As such, generate-schema popularity was classified as popular.
We found that generate-schema demonstrated a not healthy version release cadence and project activity because the last version was released a year ago. It has 1 open source maintainer collaborating on the project.
Did you know?
Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.
Product
Add secure dependency scanning to Claude Desktop with Socket MCP, a one-click extension that keeps your coding conversations safe from malicious packages.
Product
Socket now supports Scala and Kotlin, bringing AI-powered threat detection to JVM projects with easy manifest generation and fast, accurate scans.
Application Security
/Security News
Socket CEO Feross Aboukhadijeh and a16z partner Joel de la Garza discuss vibe coding, AI-driven software development, and how the rise of LLMs, despite their risks, still points toward a more secure and innovative future.