Registry / testing / json-schema-empty

json-schema-empty

JSON →
library1.1.1jsnpmunverified

Generates minimal, deterministic data from a JSON Schema. Version 1.1.1 is current. The library fills values that fit the structure of the schema (e.g., empty strings, zeros, empty arrays) rather than random data. It supports JSON Schema draft-04, including $ref, oneOf, anyOf, allOf, and enum. Unlike data generators like json-schema-faker, it prioritizes simplicity and determinism for use cases like form defaults or test fixtures.

npm install json-schema-empty
INSTALL
IMPORT
SIG · JSON-SCHEMA-EMPTY
J
json-schema-empty
testingjavascriptv1.1.1
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.

empty
import empty from 'json-schema-empty'
const empty = require('json-schema-empty')
ESM default import only. No named export.

Shows how to generate empty or minimal data based on a JSON schema with required fields and constraints.

import empty from 'json-schema-empty'; const schema = { type: 'object', properties: { name: { type: 'string' }, age: { type: 'integer', minimum: 0, maximum: 120 }, tags: { type: 'array', items: { type: 'string' }, minItems: 1 } }, required: ['name', 'age'] }; const result = empty(schema); console.log(result); // { name: '', age: 0, tags: [] }
Debug
Known issues
gotchaString schema always returns empty string, even if minLength > 0 or pattern is specified.
fix
Do not rely on generated strings to satisfy constraints. Handle string validation separately if needed.
affects: >=1.0.0
gotchaArray schema ignores maxItems and always returns the shortest array (empty unless minItems is set).
fix
If you need a specific array length, set minItems to the desired length. maxItems has no effect.
affects: >=1.0.0
gotchaObject schema only includes keys in 'required' array; other properties are omitted even if present in schema.
fix
To include optional properties, list them in required or merge with a required array.
affects: >=1.0.0
gotchaGenerated data may not be valid according to the schema due to unenforceable constraints (e.g., pattern, maxLength).
fix
Use for form defaults or structural stubs, not for strict schema validation.
affects: >=1.0.0
Errors
Common errors & fixes
TypeError: empty is not a function
Using CommonJS require with CJS build not available; npm package exports ESM only.
fix
Use import empty from 'json-schema-empty' in ESM environment or transpile with bundler.
Cannot read properties of undefined (reading 'type')
Passing an empty object or null as schema instead of a valid JSON Schema object.
fix
Ensure schema argument is a valid object with a 'type' property (or $ref).
Upgrade
Version history
1.1.1latest on npm
Audit
Dependencies

No dependency data recorded yet.

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