Registry / testing / fluent-json-schema

fluent-json-schema

JSON →
library6.0.0jsnpmunverified

fluent-json-schema is a fluent API to generate JSON Schema (draft-07) documents for Node.js and browsers. Version 6.0.0 is current, with frequent releases following Fastify ecosystem cadence. Framework agnostic, it provides runtime validation of schema keywords and constant reuse from JavaScript values. Alternative to manual schema objects or JSON Schema builders like jsonschema or ajv's schema generation. Ships TypeScript definitions with 100% coverage.

npm install fluent-json-schema
INSTALL
IMPORT
SIG · FLUENT-JSON-SCHEMA
F
fluent-json-schema
testingjavascriptv6.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.

default
import S from 'fluent-json-schema'
const S = require('fluent-json-schema')
Default import works in TypeScript with esModuleInterop. In CommonJS, use require().
S (named)
import { S } from 'fluent-json-schema'
import S from 'fluent-json-schema'
Named export S is available for native ESM or TypeScript without esModuleInterop. Do not mix default and named.
S (CommonJS)
const S = require('fluent-json-schema')
const { S } = require('fluent-json-schema')
CommonJS require returns the default export. Named destructuring is incorrect.

Builds a simple JSON Schema object with fluent methods and outputs the schema.

const S = require('fluent-json-schema'); const schema = S.object() .title('Person') .description('A person object') .prop('name', S.string().minLength(2).required()) .prop('age', S.number().minimum(0)) .prop('email', S.string().format(S.FORMATS.EMAIL)) .valueOf(); console.log(JSON.stringify(schema, null, 2)); // Output: // { // "$schema": "http://json-schema.org/draft-07/schema#", // "type": "object", // "title": "Person", // "description": "A person object", // "properties": { // "name": { "type": "string", "minLength": 2 }, // "age": { "type": "number", "minimum": 0 }, // "email": { "type": "string", "format": "email" } // }, // "required": ["name"] // }
Debug
Known issues
breakingDefault export changed from S to default in v5+
fix
Use import S from 'fluent-json-schema' or import { S } ... depending on module system.
affects: >=5.0.0
deprecatedS.FORMATS enum usage is now deprecated in favor of direct string values
fix
Use S.string().format('email') instead of S.string().format(S.FORMATS.EMAIL)
affects: >=5.5.0
gotchaS.raw() can produce invalid schemas if not used carefully
fix
Ensure raw JSON is valid JSON Schema and does not conflict with fluent keywords.
affects: all
gotchaRequired properties must be set via .required() on the property, not on the object level
fix
Use .required() as a chained call on the property, e.g., S.string().required()
affects: all
deprecatedThe .id() method is deprecated; use .$id() instead
fix
Replace .id(...) with .$id(...)
affects: >=5.0.0
Errors
Common errors & fixes
TypeError: S.object is not a function
Using named import { S } when package is CJS and esModuleInterop is false
fix
Use import * as S from 'fluent-json-schema' or const S = require('fluent-json-schema')
SyntaxError: Missing initializer in const declaration
Using const S = require('fluent-json-schema') without parentheses or split lines
fix
Ensure require call is correct: const S = require('fluent-json-schema');
Error: Unknown keyword: formatMaximum
Using custom keywords like formatMaximum without a validator that supports them (e.g., AJV)
fix
Either use a JSON Schema validator that supports custom keywords or avoid non-standard keywords. Alternatively, wrap with S.raw().
Error: .prop() must be called on an object schema
Chaining .prop() on a non-object schema (e.g., S.string().prop())
fix
Ensure .prop() is only chained after S.object()
Upgrade
Version history
6.0.0latest on npm
Audit
Dependencies

No dependency data recorded yet.

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