json-zen

Playground GitHub npm
verify(json, schema) — validates JSON against a schema string. Throws a ZenError with details if validation fails. Returns true on success.
Schema syntax: {key:type}  |  [type]  |  ?type (optional)  |  type:default  |  Aliases: s=string, n=number, b=boolean
JSON Input
Schema
Tip: {key:type, key?:type} · [type] · s n b · type:default
check(json, schema) — same as verify but returns true or false instead of throwing. Safe wrapper that never throws on validation failures.
JSON Input
Schema
Tip: {key:type, key?:type} · [type] · s n b · type:default
shape(json, schema, options?) — reshapes JSON to match the schema, filling defaults for missing/invalid fields. Returns the transformed object. Optionally pass custom type validators as options.
JSON Input
Schema
type:default fills missing/invalid fields
Output
toSchema(json, options?) — infers a schema string from any JSON value. Useful for bootstrapping a schema from real data.
Options: default type to omit (e.g. "string")  |  compact strips all :type annotations from object attributes.
JSON Input
Generated Schema
extendTypes(types) — registers custom type validators globally. A validator can be a function (value) => boolean, an array of allowed strings, or a RegExp. Then use the key name in any schema.
JSON to Validate
Schema
Uses custom types defined on the right →
Custom Types (JS)