A simple tool for instantiating JSON Schemas.
JavaScript
Latest commit b30b691 Sep 28, 2016 @tomarad committed on GitHub Merge pull request #12 from tomarad/version/0.4.2
Version 0.4.2

README.md

JSON-Schema-Instantiator

A simple tool for instantiating JSON Schemas, with Angular support!

Installing

Node.js

npm install json-schema-instantiator

AngularJS

bower install angular-schema-instantiator

Using

Node.js

var instantiator = require('json-schema-instantiator');

...

var schema = {
    "type": "object",
    "properties": {
        "title": {
            "type": "string",
            "default": "Example"
        },
        "description": {
            "type": "string"
        }
    },
    "required": ["title"]
};

instance = instantiator.instantiate(schema);
// instance === { title: "Example", description: "" }

instance = instantiator.instantiate(schema, {requiredPropertiesOnly: true});
// instance === { title: "Example", description: "" }

instance = instantiator.instantiate(schema, {requiredPropertiesOnly: false});
// instance === { title: "Example" }

AngularJS

Add the sources to index.html:

<script src="json-schema-instanciator/src/instantiator.js"></script>
<script src="json-schema-instanciator/src/angular-instantiator.js"></script>

Include the module:

angular.module('myApp', ['schemaInstantiator'])

...

Inject the InstantiatorService and use it:

...

.controller({
    MyCtrl: ['InstantiatorService', function(Instantiator) {
        var schema = {
            type: "string",
            default: "Hello!"
        };

        console.log(Instantiator.instantiate(schema));
        // Hello!
    }]
})

...