JSON Schema validation package for Julia
Author fredo-dedup
17 Stars
Updated Last
1 Year Ago
Started In
June 2018


JSON instance validation using JSON Schemas

Build Status codecov


JSONSchema.jl is a JSON validation package for the julia programming language. Given a validation schema this package can verify if any JSON instance meets all the assertions defining a valid document.

This package has been validated with the JSON Schema Test Suite for draft v4 and v6.


Create a Schema object by passing a string:

julia> my_schema = Schema("""{
            "properties": {
                "foo": {},
                "bar": {}
            "required": ["foo"]

passing a dictionary with the same structure as a schema:

julia> my_schema = Schema(
                "properties" => Dict(
                    "foo" => Dict(),
                    "bar" => Dict()
                "required" => ["foo"]

or by passing a parsed JSON file containing the schema:

julia> my_schema = Schema(JSON.parsefile(filename))

Check the validity of a given JSON instance by calling validate with the JSON instance x to be tested and the schema. If the validation succeeds, validate returns nothing:

julia> data_pass = Dict("foo" => true)
Dict{String,Bool} with 1 entry:
  "foo" => true

julia> validate(my_schema, data_pass)

If the validation fails, a struct is returned that, when printed, explains the reason for the failure:

julia> data_fail = Dict("bar" => 12.5)
Dict{String,Float64} with 1 entry:
  "bar" => 12.5

julia> validate(my_schema, data_fail)
Validation failed:
path:         top-level
instance:     Dict("bar"=>12.5)
schema key:   required
schema value: ["foo"]

As a short-hand for validate(schema, x) === nothing, use Base.isvalid(schema, x).