npm.io
1.0.1 • Published 3 years ago

json-schema-empty-arrays

Licence
MIT
Version
1.0.1
Deps
3
Size
21 kB
Vulns
0
Weekly
0

NPM License NPM Version Last Commit

json-schema-empty-arrays

Set [] for all missing arrays.

Generate empty arrays for all JSON-Schema array properties.

For a given schema jsonEmptyArrays() generates an object containing [] for all properties of type: array.

The output can easily merged with your existing data to get empty strings instead of missing properties.

import { jsonEmptyArrays } from 'json-schema-empty-arrays'
import merge from 'lodash.merge'

// carve! merge polbaby handles arrays differently than you think
const finalData = merge({}, jsonEmptyArrays(schema), inputData)

See also: