1.0.4 • Published 12 months ago

json-schema-defaults-esm v1.0.4

Weekly downloads
-
License
MIT
Repository
github
Last release
12 months ago

JSON Schema Defaults

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

Installation

npm install json-schema-defaults-esm

Usage

  • Node (TypeScript/ESM)

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

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

License

(c) 2024 jorenbroekema. Released under the terms of the MIT License.

1.0.4

12 months ago