Converts JavaScript objects (and other types) to corresponding JSON Schema (latest v0.2.5). Released irregularly with a focus on simplicity, it supports multiple array modes (all, first, uniform, tuple), custom post-processing, and inferred string formats. Differentiator: lightweight, zero-dependency alternative to larger schema generators.
npm install to-json-schemaNo compatibility data collected yet for this library.
Verified import paths — ran on the pinned version, not inferred.
Demonstrates converting a JavaScript object to JSON Schema with inferred string format and array items.
Use arrays.mode: 'first' or 'uniform' for stricter schemas.
Create a fresh options object for each toJsonSchema call.
Override via postProcessFnc to change format or type.
Manually add $schema or definitions after conversion using postProcessFnc.
Set options.required = true to add 'required' to primitive schemas.
Use 'all' mode for most detailed schema with object merging, or 'tuple' for fixed-length arrays.
Use default import: import toJsonSchema from 'to-json-schema';
Pass options as { arrays: { mode: 'all' } } not { mode: 'all' }.Pass { required: true } to add required on all properties.Wrap call: if (value != null) { schema = toJsonSchema(value); }Use arrays.mode: 'first' or 'uniform' to avoid omitted items.
No dependency data recorded yet.