Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/nodecg/json-schema-defaults
A library and CLI tool for generating a default value from a JSON schema
https://github.com/nodecg/json-schema-defaults
Last synced: about 14 hours ago
JSON representation
A library and CLI tool for generating a default value from a JSON schema
- Host: GitHub
- URL: https://github.com/nodecg/json-schema-defaults
- Owner: nodecg
- License: mit
- Created: 2023-01-26T15:45:31.000Z (almost 2 years ago)
- Default Branch: main
- Last Pushed: 2023-01-27T18:52:43.000Z (almost 2 years ago)
- Last Synced: 2024-11-14T16:24:15.419Z (2 days ago)
- Language: TypeScript
- Size: 806 KB
- Stars: 0
- Watchers: 2
- Forks: 1
- Open Issues: 1
-
Metadata Files:
- Readme: README.md
- Changelog: CHANGELOG.md
- License: LICENSE
Awesome Lists containing this project
README
# JSON Schema Defaults
> A library and CLI tool for generating a default value from a JSON schema
## Installation
```sh
npm install @nodecg/json-schema-defaults
```## Usage
- Node (TypeScript/ESM)
```js
import defaults from 'json-schema-defaults';
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.
```ts
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
```sh
npm test
```## Contributors
- Eugene Tsypkin @jhony-chikens (original author of [`json-schema-defaults`](https://www.npmjs.com/package/json-schema-defaults) on npm)
- Alex Van Camp @alvancamp## License
(c) 2023 The NodeCG Project. Released under the terms of the MIT License.