# json-schema-defaults

> Generate JSON object from default values in JSON Schema

Latest version **0.4.0** (published 2018-02-13) · MIT license · 0 weekly downloads

## Install

```sh
npm install json-schema-defaults
pnpm add json-schema-defaults
yarn add json-schema-defaults
bun add json-schema-defaults
```

Provides the command `json-schema-defaults`.

## Health

**Score 15/100 (F)** — status: abandoned.

Positive: no vulnerabilities.

Warnings: low downloads; no types; no esm support; pre 1.0.

Negative: abandoned; low maintenance score.

## Facts

| | |
|---|---|
| Version | 0.4.0 |
| Published | 2018-02-13 |
| First published | 2014-04-29 |
| Weekly downloads | 0 |
| License | MIT |
| TypeScript types | none |
| Module format | CommonJS |
| Dependencies | 1 |
| Unpacked size | 112.5 KB |
| Known vulnerabilities | 0 |
| Install scripts | no |
| Author | Chute |
| Maintainers | petrbela |
| Keywords | json, schema |

## Links

- npm: https://www.npmjs.com/package/json-schema-defaults
- Repository: https://github.com/chute/json-schema-defaults
- Homepage: https://github.com/chute/grunt-json-schema-defaults
- Issues: https://github.com/chute/json-schema-defaults/issues
- npm.io page: https://npm.io/package/json-schema-defaults

## Dependencies (1)

- [argparse](https://npm.io/package/argparse.md) ^1.0.9

## Alternatives

- [@mapbox/jsonlint-lines-primitives](https://npm.io/package/@mapbox/jsonlint-lines-primitives.md) — 5.3M weekly downloads
- [reftools](https://npm.io/package/reftools.md) — 3.5M weekly downloads
- [@hey-api/openapi-ts](https://npm.io/package/@hey-api/openapi-ts.md) — 3.5M weekly downloads
- [@mapbox/geojson-rewind](https://npm.io/package/@mapbox/geojson-rewind.md) — 2.4M weekly downloads
- [turbo-stream](https://npm.io/package/turbo-stream.md) — 1.7M weekly downloads

## Recent versions

- 0.4.0 (latest) — 2018-02-13
- 0.3.0 — 2016-12-26
- 0.2.0 — 2016-08-08
- 0.1.1 — 2015-03-17
- 0.1.0 — 2015-01-30
- 0.0.2 — 2014-05-04
- 0.0.1 — 2014-04-29

## README

# JSON Schema Defaults  [![Build Status](https://travis-ci.org/chute/json-schema-defaults.svg?branch=master)](https://travis-ci.org/chute/json-schema-defaults)

> Generate JSON object from default values in JSON Schema

Works both in node and browser.

## Installation

- npm

  ```sh
  npm install json-schema-defaults
  ```

- bower

  ```sh
  bower install json-schema-defaults
  ```

- manual

  Download [lib/defaults.js](lib/defaults.js)

## Usage

- CommonJS (node.js)

  ```js
  var defaults = require('json-schema-defaults');
  defaults({ ... });
  ```

- RequireJS

  ```js
  // in require.js config
  paths: {
    'defaults': './path/to/lib/defaults.js'
  }

  // in a file
  define(['defaults'], function(defaults) {
    defaults({ ... });
  });
  ```

- standalone

  ```js
  window.jsonSchemaDefaults({ ... });
  ```

  If the standalone version causes any conflict with existing `jsonSchemaDefaults` global variable,
  you can return back the original variable:

  ```js
  var defaults = window.jsonSchemaDefaults.noConflict();
  // `window.jsonSchemaDefaults` now points to the original variable
  // `defaults` points to this script
  defaults({ ... });
  ```

- CLI

  If installed globally:

  ```sh
  json-schema-defaults schema.json
  ```

  If locally:

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

  Custom indentation (defaults to 2):

  ```sh
  json-schema-defaults --indent 4 schema.json
  ```

  Write into a file:

  ```sh
  json-schema-defaults schema.json > defaults.json
  ```

## Documentation

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

```js
var 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

```sh
npm test
```

Or individually

```sh
# in node
./node_modules/.bin/jasmine-node test/

# in browser
./node_modules/karma/bin/karma start
```


## Contributors

* Eugene Tsypkin @jhony-chikens


## License

(c) 2015 Chute Corporation. Released under the terms of the MIT License.

---
_Source: https://npm.io/package/json-schema-defaults · Machine-readable twin of the npm.io package page. Health data is recomputed on every publish._
