Getting started with jsonschema
Remarks#
What is JSON Schema?
JSON Schema is a vocabulary that allows you to validate, annotate, and manipulate JSON documents.
A JSON Schema is itself a JSON document and requires a third party library to validate data against it.
It is currently a draft IETF standard allowing consistent expectation from implementations based on the standard specification.
Vocabularies
Published vocabularies
- JSON Schema Core the basic foundation of JSON Schema
- JSON Schema Validation the validation keywords of JSON Schema
- JSON Hyper-Schema the hyper-media keywords of JSON Schema
Proposed vocabularies requiring discussion, feedback and review
- JSON Schema API API documentation keyword proposal
- JSON Schema UI the UI keywords for consistent UI generation proposal
Implementations
A list of implementations is maintained in the GitHub repository. The list of supported languages currently lists validators for:
ActionScript 3, C, C++, Clojure, Dart, Erlang, Go, Haskell, Java, JavaScript, .NET, PHP, Perl, Python and Ruby
There are also UI generators, data parsers, schema editors, documentation generators and IDE support.
Basic example validation schema
{
"title": "Person",
"type": "object",
"properties": {
"firstName": {
"type": "string"
},
"lastName": {
"type": "string"
},
"age": {
"description": "Age in years",
"type": "integer",
"minimum": 0
}
},
"required": ["firstName", "lastName"]
}
Results
// Valid
{
"firstName": "Jason",
"lastName": "Voorhees"
}
// Valid
{
"firstName": "Jason",
"lastName": "Voorhees",
"age": 47
}
// Invalid - no lastName
{
"firstName": "Jason",
"age": 47
}
// Invalid - age is not integer
{
"firstName": "Jason",
"lastName": "Voorhees",
"age": "47"
}