Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

json-schema-defaults

Package Overview
Dependencies
Maintainers
1
Versions
7
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

json-schema-defaults

Generate JSON object from default values in JSON Schema

  • 0.4.0
  • latest
  • Source
  • npm
  • Socket score

Version published
Maintainers
1
Created
Source

JSON Schema Defaults Build Status

Generate JSON object from default values in JSON Schema

Works both in node and browser.

Installation

  • npm

    npm install json-schema-defaults
    
  • bower

    bower install json-schema-defaults
    
  • manual

    Download lib/defaults.js

Usage

  • CommonJS (node.js)

    var defaults = require('json-schema-defaults');
    defaults({ ... });
    
  • RequireJS

    // in require.js config
    paths: {
      'defaults': './path/to/lib/defaults.js'
    }
    
    // in a file
    define(['defaults'], function(defaults) {
      defaults({ ... });
    });
    
  • standalone

    window.jsonSchemaDefaults({ ... });
    

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

    var defaults = window.jsonSchemaDefaults.noConflict();
    // `window.jsonSchemaDefaults` now points to the original variable
    // `defaults` points to this script
    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.

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

npm test

Or individually

# 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.

Keywords

FAQs

Package last updated on 13 Feb 2018

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc