@nodecg/json-schema-defaults
TypeScript icon, indicating that this package has built-in type declarations

1.0.4 • Public • Published

JSON Schema Defaults

A library and CLI tool for generating a default value from a JSON schema

Installation

npm install @nodecg/json-schema-defaults

Usage

  • Node (TypeScript/ESM)

    import defaults from 'json-schema-defaults';
    defaults({ ... });
  • CLI

    If installed globally:

    json-schema-defaults schema.json

    If locally:

    ./node_modules/.bin/json-schema-defaults schema.json

    Custom indentation (defaults to 2):

    json-schema-defaults --indent 4 schema.json

    Write into a file:

    json-schema-defaults schema.json > defaults.json

Documentation

Call defaults with JSON Schema. The default values will be extracted as a JSON.

const json = defaults({
  "title": "Album Options",
  "type": "object",
  "properties": {
    "sort": {
      "type": "string",
      "default": "id"
    },
    "per_page": {
      "default": 30,
      "type": "integer"
    }
  }
});

// would return
{
  sort: 'id',
  per_page: 30
}

For more examples, see the tests.

Development

Run tests

npm test

Contributors

  • Eugene Tsypkin @jhony-chikens (original author of json-schema-defaults on npm)
  • Alex Van Camp @alvancamp

License

(c) 2023 The NodeCG Project. Released under the terms of the MIT License.

Readme

Keywords

Package Sidebar

Install

npm i @nodecg/json-schema-defaults

Weekly Downloads

466

Version

1.0.4

License

MIT

Unpacked Size

9.71 kB

Total Files

10

Last publish

Collaborators

  • alvancamp
  • hoishin