Skip to content

SrAceves/JSONSchema.jl

 
 

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

45 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

JSONSchema

JSON instance validation using JSON Schemas

Build Status Build status Coverage Status codecov

Overview

JSONSchema.jl is a JSON validation package for the julia programming language. Given a validation Schema (see http://json-schema.org/specification.html) this package can verify if any JSON instance follows all the assertions defining a valid document.

This package has been validated with the test suite of the JSON Schema org (https://github.com/json-schema-org/JSON-Schema-Test-Suite) for draft v4 and v6.

API

First step is to create a Schema object :

# using a String as input
myschema = Schema("""
 {
    "properties": {
       "foo": {},
       "bar": {}
    },
    "required": ["foo"]
 }""")  

# or using a pre-processed JSON as input, using the JSON package
sch = JSON.parsefile(filepath)
myschema = Schema(sch)

You can then check the validity of a given JSON instance by calling isvalid with the JSON instance to be tested and the Schema:

isvalid( JSON.parse("{ "foo": true }"), myschema) # true
isvalid( JSON.parse("{ "bar": 12.5 }"), myschema) # false

The JSON instance should be provided as a pre-processed JSON object created with the JSON package.

Should you need a diagnostic message to understand the cause of rejection you can use the diagnose() function. diagnose() will either return nothing if the instance is valid or a message detailing which assertion failed.

diagnose( JSON.parse("{ "foo": true }") , myschema)
# nothing
diagnose( JSON.parse("{ "bar": 12.5 }") , myschema)
# "in [] : required property 'foo' missing"

About

JSON Schema validation package for Julia

Resources

License

Stars

Watchers

Forks

Packages

No packages published

Languages

  • Julia 100.0%