Socket
Book a DemoInstallSign in
Socket

json-schema-preset

Package Overview
Dependencies
Maintainers
1
Versions
2
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

json-schema-preset

Produce a suitable default template / preset based on a JSON-Schema.

latest
Source
npmnpm
Version
1.0.1
Version published
Weekly downloads
3
-25%
Maintainers
1
Weekly downloads
 
Created
Source

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

Keywords

JSON

FAQs

Package last updated on 09 Oct 2023

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts