json-to-schema-generator-v2
v1.0.3
Published
A lightweight, zero-dependency Node.js utility to dynamically generate standard JSON Schema from any JSON object.
Downloads
529
Maintainers
Readme
json-to-schema-generator
⚠️ Status: Stable | 📦 Version: 1.0.0 | 🧩 Dependencies: Zero
A lightweight, zero-dependency Node.js utility that dynamically generates standard JSON Schema (Draft-07 style) from any valid JavaScript/JSON object. It recursively processes nested structural objects, maps array types, and uses smart primitives deduction.
🚀 Features
- ⚡ Zero Dependencies: Keeps your production bundles fast, ultra-lightweight, and free of security dependency hell.
- 🧠 Smart Type Extraction: Distinguishes between integers and standard floating-point
numbervalues via modern JavaScript validations. - 🌲 Deep Recursion: Safely walks down deeply-nested complex arrays, objects, and key pairs.
- 📋 Auto-Enforced Validation: Instantly maps structural discovery to strict
requiredrule blocks for safe validation strategies.
📦 Installation
To save this package in your production project pipeline, run:
npm i json-to-schema-generator-v2Usage
const generateSchema = require('json-to-schema-generator-v2');
const payload = {
id: 4501,
name: "Enterprise Service Module",
isActive: true,
metrics: {
latency: 14.2,
retries: 3
},
tags: ["cloud", "backend"]
};
// Generate standard Draft-07 JSON Schema
const schema = generateSchema(payload);
console.log(JSON.stringify(schema, null, 2));Example Output
{
"type": "object",
"properties": {
"id": { "type": "integer" },
"name": { "type": "string" },
"isActive": { "type": "boolean" },
"metrics": {
"type": "object",
"properties": {
"latency": { "type": "number" },
"retries": { "type": "integer" }
},
"required": ["latency", "retries"]
},
"tags": {
"type": "array",
"items": { "type": "string" }
}
},
"required": ["id", "name", "isActive", "metrics", "tags"],
"title": "GeneratedSchema",
"$schema": "[http://json-schema.org/draft-07/schema#](http://json-schema.org/draft-07/schema#)"
}