jsonschemaGetting 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

Proposed vocabularies requiring discussion, feedback and review

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"
}