grunt-jsonschema v0.0.4
Simple and fast JSON schema validator for grunt.
Getting Started
This plugin requires Grunt ~0.4.5
If you haven't used Grunt before, be sure to check out the Getting Started guide, as it explains how to create a Gruntfile as well as install and use Grunt plugins. Once you're familiar with that process, you may install this plugin with this command:
npm install grunt-jsonschema --save-dev
Once the plugin has been installed, it may be enabled inside your Gruntfile with this line of JavaScript:
grunt.loadNpmTasks('grunt-jsonschema');
The "jsonschema" task
Overview
In your project's Gruntfile, add a section named jsonschema
to the data object passed into grunt.initConfig()
.
grunt.initConfig({
jsonschema: {
options: {
file: 'test/files/person.json',
schema: 'test/schemas/person.json'
}
}
});
Options
options.file
Type: String
Default value: null
path to json file that wants to be validated.
options.schema
Type: String
Default value: null
jsonschema path.
Single File
grunt.initConfig({
jsonschema: {
all:{
options: {
file: 'test/files/person.json',
schema: 'test/schemas/person.json'
}
}
}
});
Multiple Files and multiple schemas
grunt.initConfig({
jsonschema: {
all:{
options: {
files: [
{
file: 'test/files/person.json',
schema: 'test/schemas/person.json'
},
{
file: 'test/files/posts.json',
schema: 'test/schemas/posts.json'
}
]
}
}
}
});
Multiple Files one schema
grunt.initConfig({
jsonschema: {
all:{
options: {
schema: 'test/schemas/person.json',
files: [
'test/files/person.json',
'test/files/person2.json'
]
}
}
}
});
One file and Complex Schema
grunt.initConfig({
jsonschema: {
all:{
options: {
file: 'test/files/person.json',
schema: {
main: 'test/schemas/person_ref.json',
refs: [
'test/schemas/address.json'
]
}
}
}
}
});
Multiple files and Complex Schema
grunt.initConfig({
jsonschema: {
all:{
options: {
files: [
'test/files/person.json',
'test/files/person2.json'
],
schema: {
main: 'test/schemas/person_ref.json',
refs: [
'test/schemas/address.json'
]
}
}
}
}
});
Contributing
In lieu of a formal styleguide, take care to maintain the existing coding style. Add unit tests for any new or changed functionality. Lint and test your code using Grunt.
Release History
- v0.0.4 -> Sunday, September 7, 2014 | Release notes