1.0.1 • Published 1 year ago

json-schema-preset v1.0.1

Weekly downloads
-
License
MIT
Repository
github
Last release
1 year ago

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