Giter Club home page Giter Club logo

json_validation's Introduction

JsonValidation

JsonValidation validates JSON according to a JSON Schema.

It is designed to validate as quickly as possible.

Current limitations

  • The library can only say whether a record is valid or not. In the event that a record is not valid, it will not say why.
  • The library will only validate against draft v4 of the JSON Schema specification.

Installation

Add this line to your application's Gemfile:

gem 'json_validation'

And then execute:

$ bundle

Or install it yourself as:

$ gem install json_validation

Usage

Load the library:

require "json_validation"

Build a validator from a hash representing a JSON schema:

validator = JsonValidation.build_validator(schema)

Load a validator from a schema at a URL or path:

validator = JsonValidation.load_validator(uri)

Use the validator to validate whether a record validates against a schema.

validator.validate(record)
# => returns true or false

Format validation

To validate a record against a format, define a validator class with a #validate method:

class DateTimeFormatValidator
  def validate(record)
    Date.parse(record)
    true
  rescue ArgumentError
    false
  end
end

Then, register the validator:

JsonValidation.add_format_validator("date-time", DateTimeFormatValidator)

Contributing

If you find an example of a record being incorrectly validated against a schema, please raise an issue on GitHub.

You can run the tests with:

$ bundle exec rake test

A handful of tests require internet access.

json_validation's People

Contributors

inglesp avatar

Watchers

 avatar  avatar

Forkers

dominicsayers

json_validation's Issues

There should be a metaschema

So that I can validate my schemas.

Note that the schema provided by json-schema (resources/draft-04.json) includes a regex formatter which is optional under the spec...

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.