Registry / devops / genson-js

genson-js

JSON →
library0.0.8jsnpmunverified

genson-js (v0.0.8) is a TypeScript/JavaScript library for generating JSON Schemas from JSON objects and merging multiple schemas. It ports the Python GenSON library, providing functions like createSchema, mergeSchemas, createCompoundSchema, extendSchema, areSchemasEqual, and isSubset. It ships TypeScript types and is designed for lightweight schema inference and composition. Released occasionally with basic functionality; no recent updates. Differentiated by its focus on schema merging and TypeScript support.

npm install genson-js
INSTALL
IMPORT
SIG · GENSON-JS
G
genson-js
devopsjavascriptv0.0.8
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.

createSchema
✓ import { createSchema } from 'genson-js'
✗ const createSchema = require('genson-js').createSchema
Proper ESM import. CJS require works but TypeScript may need esModuleInterop.
mergeSchemas
✓ import { mergeSchemas } from 'genson-js'
✗ import { mergeSchemas } from 'genson-js/mergeSchemas'
Direct named import from package root.
ValueType
✓ import { ValueType } from 'genson-js'
✗ import ValueType from 'genson-js'
ValueType is a named export, not default.

Demonstrates creating a JSON Schema from a sample object using createSchema.

import { createSchema } from 'genson-js'; const schema = createSchema({ userName: 'smith', languages: ['c++', 'java'], age: 40, }); console.log(JSON.stringify(schema, null, 2)); /* Output: { "type": "object", "properties": { "userName": { "type": "string" }, "languages": { "type": "array", "items": { "type": "string" } }, "age": { "type": "integer" } }, "required": ["userName", "languages", "age"] } */
Debug
Known issues
gotchaThe library does not support all JSON Schema draft versions or features like $ref, definitions, or conditional validation.
fix
For complex schemas, consider using libraries like ajv or json-schema-generator.
affects: >=0.0.0
gotchaThe ValueType enum values are strings (e.g., 'string', 'number', 'integer', etc.). Using numeric or other types may cause unexpected behavior.
fix
Always use ValueType enum or the corresponding string literal for type values.
affects: >=0.0.0
gotchacreateCompoundSchema does not deduplicate or simplify types; duplicate schemas may result in redundant entries.
fix
Manually merge results if optimization is needed.
affects: >=0.0.0
Errors
Common errors & fixes
Cannot find module 'genson-js' or its corresponding type declarations.
Missing TypeScript types or module resolution issue.
fix
Ensure npm install genson-js is run, and tsconfig.json has 'moduleResolution': 'node' or 'node16'.
TypeError: createSchema is not a function
Using default import instead of named import.
fix
Use import { createSchema } from 'genson-js'.
Uncaught TypeError: (0 , _genson_js.createSchema) is not a function
Using CJS require incorrectly or mixing module systems.
fix
Use const { createSchema } = require('genson-js') if in CommonJS environment.
Upgrade
Version history
0.0.8latest on npm
Audit
Dependencies

No dependency data recorded yet.

Agent activity
7 hits · last 30 days
node
6
Resources
genson-js — npm install genson-js · libregistry