json-schema-preset
TypeScript icon, indicating that this package has built-in type declarations

1.0.1 • Public • Published

npm version

json-schema-preset

Produce a suitable default template / preset based on a JSON-Schema, e.g. for pre-filling a form.

It is in the spirit of json-schema-empty. json-schema-empty is different in that it closely observes the required properties and only adds required values.

json-schema-preset on the other hand copies default values not caring if they are required or not. It also ensures that no string properties are null but preset with an empty string (""). Arrays without defaults are replaced by [].

You can generate a preset for a form etc. like this:

import { jsonPreset } from 'json-schema-preset';

const preset = jsonPreset(schema);

If you want to ensure that an existing object has all missing properties filled in by jsonPreset() give it as a second parameter:

import { jsonPreset } from 'json-schema-preset';

const dataWithPreset = jsonPreset(schema, { data: 'foobar' });

See also

/json-schema-preset/

    Package Sidebar

    Install

    npm i json-schema-preset

    Weekly Downloads

    11

    Version

    1.0.1

    License

    MIT

    Unpacked Size

    18.7 kB

    Total Files

    16

    Last publish

    Collaborators

    • mdornseif