json-schema
's direct dependencies. Data on all dependencies, including transitive ones, is available via CSV download.Name | Version | Size | License | Type | Vulnerabilities |
---|
JSON Schema is an efficient and lightweight implementation of the original core elements of JSON schema validation and specifications. It encompasses the earlier draft specification of JSON Schema, and is considered "finished", aiming to maintain stability both in behavior and size. This allows for the creation, validation, and description of data structures for JavaScript Object Notation (JSON) data formats. Keep in mind, this package doesn't include the latest specifications or implement the latest versions of JSON Schema.
Incorporating JSON Schema into your JavaScript project starts with installing it via npm using the command npm install json-schema
. Following installation, you can require the package in your code and use it to validate JSON data against a particular schema.
Here is a simple usage example:
var Validator = require('json-schema').Validator;
var v = new Validator();
// defining a schema
var schema = {
"type": "object",
"properties": {
"name": { "type": "string" },
"age": { "type": "integer" }
},
"required": ["name"]
};
// defining data
var data = {
"name": "John",
"age": 30
};
// validation
var validation = v.validate(data, schema);
if (validation.valid) {
console.log('Valid!');
} else {
console.log('Invalid: ' + validation.errors.join(', '));
}
In this example, we define a JSON schema for an object with a string property 'name' and an integer property 'age'. 'Name' is required. The v.validate(data, schema)
function is then used to validate a data object against the defined schema.
The key documentation for this package is sadly not housed in this repository. Therefore, for the most recent JSON schema specifications and implementations, you should visit the official JSON Schema site. Furthermore, the latest repository can be found on GitHub at https://github.com/json-schema-org/json-schema-spec where you can access more up-to-date information and developments for JSON Schema.