Registry / testing / json-schema-it

json-schema-it

JSON →
library1.2.24jsnpmunverified

json-schema-it is a lightweight, type-safe JSON Schema generator for JavaScript/TypeScript (v1.2.24, stable). It converts JavaScript values—primitives, objects, and arrays—into JSON Schema objects without custom options or configuration. It ships TypeScript types and supports both ESM and CJS. Key differentiators: zero dependencies, no configuration, and strictly clamps to standard JSON typeof types (e.g., null is not allowed). It throws on undefined, Symbol, and BigInt. Released via Release Please on GitHub with community maintenance under the Braze organization. Suitable for validation, documentation generation, and API schema inference.

npm install json-schema-it
INSTALL
IMPORT
SIG · JSON-SCHEMA-IT
J
json-schema-it
testingjavascriptv1.2.24
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
import { generateSchema } from 'json-schema-it'
import generateSchema from 'json-schema-it'
Default import does not work; must use named import.
generateSchema
const { generateSchema } = require('json-schema-it')
CJS destructured require is the correct pattern.
generateSchema
import { generateSchema } from 'json-schema-it'
const generateSchema = require('json-schema-it')
Do not assign the whole module; destructure the export.

Demonstrates generating a JSON Schema from a JavaScript object with various types.

import { generateSchema } from 'json-schema-it'; const schema = generateSchema({ productId: 1, productName: 'A green door', price: 12.5, tags: ['home', 'green'], }); console.log(JSON.stringify(schema, null, 2)); // Output: // { // "type": "object", // "properties": { // "productId": { "type": "integer" }, // "productName": { "type": "string" }, // "price": { "type": "number" }, // "tags": { "type": "array", "items": { "type": "string" } } // } // }
Debug
Known issues
breakingNull values are not valid JSON; passing null will throw a TypeError.
fix
Pass only valid JSON values (string, number, boolean, object, array). Use e.g. generateSchema({key: null}) for objects containing null.
affects: >=1.0.0
breakingUndefined values are not allowed; generateSchema(undefined) throws.
fix
Exclude undefined from input or use a default value.
affects: >=1.0.0
deprecatedNo deprecated features known.
fix
N/A
affects: >=1.0.0
gotchaArray items must all be of the same type; mix types yield the type of the first item.
fix
Ensure consistency or use a different schema library for mixed arrays.
affects: >=1.0.0
Errors
Common errors & fixes
TypeError: Invalid JSON value: undefined
generateSchema received undefined directly or within an object property.
fix
Do not pass undefined; use null or exclude the property.
TypeError: Invalid JSON value: Symbol()
generateSchema received a Symbol, which is not valid JSON.
fix
Convert Symbol to string before passing.
TypeError: Invalid JSON value: 123n
generateSchema received a BigInt, which is not valid JSON.
fix
Convert BigInt to number or string.
Upgrade
Version history
1.2.24latest on npm
Audit
Dependencies

No dependency data recorded yet.

Agent activity
11 hits · last 30 days
node
10
Amazon
1
Resources
json-schema-it — npm install json-schema-it · libregistry