Coder Social home page Coder Social logo

jsonschema.jl's Introduction

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"

jsonschema.jl's People

Contributors

fredo-dedup avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.