8000 GitHub - dominicsayers/json_validation: JsonValidation validates JSON according to a JSON Schema. · GitHub
[go: up one dir, main page]

Skip to content
This repository was archived by the owner on Oct 25, 2022. It is now read-only.
dominicsayersPublic archive

About

JsonValidation validates JSON according to a JSON Schema.

Resources

Code of conduct

Stars

0 stars

Watchers

1 watching

Forks

 
 

Latest commit

 

History

52 Commits

Folders and files

Repository files navigation

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.

About

JsonValidation validates JSON according to a JSON Schema.

Resources

Code of conduct

Stars

0 stars

Watchers

1 watching

Forks

Releases

Packages

Used by

Contributors

Languages

0