Registry / devops / functional-json-schema

functional-json-schema

JSON →
library1.0.0jsnpmunverified

A JavaScript library for building JSON Schema objects using a functional DSL. v1.0.0 (stable, no recent updates). Provides functions to define schema properties, types, arrays, enums, definitions, and $refs in a composable way. Supports Draft-06 and Draft-07. Differentiators: programmatic schema construction with nested object syntax, built-in type helpers, and definition management. Lightweight, no runtime dependencies.

npm install functional-json-schema
INSTALL
IMPORT
SIG · FUNCTIONAL-JSON-SC
F
functional-json-schema
devopsjavascriptv1.0.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.

schema
import * as schema from 'functional-json-schema'
import schema from 'functional-json-schema'
Default export does not exist; use namespace import.
types
import { types } from 'functional-json-schema'
Named import for type helpers is also valid.
definition
import { definition } from 'functional-json-schema'
import { define } from 'functional-json-schema'
Exported function is `definition`, not `define`.
JsonSchema
import * as schema from 'functional-json-schema'; const JsonSchema = schema.schema(props, definitions, options)
const JsonSchema = schema(props)
`schema` is the main function, not a default export. Always invoke as `schema.schema()` or import `schema` function directly.

Shows basic usage of `schema` and `types.type` to build a JSON Schema object in CommonJS style.

const { schema, types } = require('functional-json-schema'); const jsonSchema = schema( { name: types.type('string', { required: true }), age: types.type('number'), }, null, { schema: 'http://json-schema.org/draft-06/#' } ); console.log(JSON.stringify(jsonSchema, null, 2));
Debug
Known issues
gotchaNamespace import is required; default export does not exist.
fix
Use `import * as schema from 'functional-json-schema'` instead of `import schema from 'functional-json-schema'`.
affects: >=1.0.0
deprecatedThe library is based on Draft-06; Draft-07 might have differences.
fix
Use `{ schema: 'http://json-schema.org/draft-07/schema#' }` option if upgrading to Draft-07.
affects: >=1.0.0
gotchaArray items with `types.arrayOf` must define item type; missing type leads to invalid schema.
fix
Always provide a type or definition to `arrayOf`, e.g., `types.arrayOf(types.type('string'))`.
affects: >=1.0.0
gotchaDefinitions passed as second argument must be an object with definition names as keys; incorrect format breaks output.
fix
Ensure second argument is an object like `{ User: { ... } }` or `null` if no definitions.
affects: >=1.0.0
Errors
Common errors & fixes
TypeError: schema is not a function
Importing as default export instead of namespace import.
fix
Use `import * as schema from 'functional-json-schema'` or `const schema = require('functional-json-schema')`.
Error: Invalid schema: type must be a string
Passing invalid type string to `types.type`.
fix
Check supported types: 'string', 'number', 'boolean', 'object', 'array', 'null'.
Error: Definition 'User' is not defined
Using `types.definition('User')` without providing definitions in second argument.
fix
Pass definitions object as second argument to `schema()`: `schema(properties, { User: {...} })`.
Upgrade
Version history
1.0.0latest on npm
Audit
Dependencies

No dependency data recorded yet.

Agent activity
4 hits · last 30 days
node
4
Resources
functional-json-schema — npm install functional-json-schema · libregistry