Giter Club home page Giter Club logo

json-schema's Introduction

Ruby JSON Schema Validator

This library is intended to provide Ruby with an interface for validating JSON objects against a JSON schema conforming to JSON Schema Draft 3. The project originally started as a fork of Constellation’s ruby-jsonschema project, but differences in the JSON schema draft versions implemented as well as assumptions made by the ruby-jsonschema library forced this to become a new project.

Usage

Install:

gem install json-schema

If downloading the git repo, build the gem and install it:

$ rake package
$ gem install pkg/json-schema-0.1.6.gem
require 'rubygems'
require 'json-schema'

JSON::Validator.validate('schema.json', 'data.json')

schema = {
  "type" => "object",
  "properties" => {
    "a" => {"type" => "integer", "required" => true}
  }
}

data = {
  "a" => 5
}

JSON::Validator.validate(schema, data)

data = [data,data,data]
JSON::Validator.validate(schema, data, :list => true)

data = {
  "a" => "taco"
}

begin
  JSON::Validator.validate2(schema, data)
rescue ValidationError
  puts $!.message
end

Currently implemented

The following core schema definitions are currently implemented:

  • type
  • properties
  • patternProperties
  • additionalProperties
  • items
  • additionalItems
  • required
  • dependencies
  • minimum
  • maximum
  • exclusiveMinimum
  • exclusiveMaximum
  • minItems
  • maxItems
  • uniqueItems
  • pattern
  • minLength
  • maxLength
  • enum
  • title
  • description
  • divisibleBy
  • disallow
  • extends
  • id
  • $ref (this implementation only follows slash-delimited fragment resolution)

Not implemented

The following core schema definitions are not implemented:

  • format – Some of the formats listed will be supported, others are fairly vague in their definition and may be left out
  • default – This library aims to solely be a validator and does not modify an object it is validating.
  • $schema – Support for this will come later, possibly with the ability to validate against other JSON Schema draft versions

In addition, the following hyper schema attributes are not implemented at this time:

  • links
  • fragmentResolution (only handles default slash-delimited)
  • contentEncoding
  • pathStart

To Do

  • (Much) More testing
  • Documentation
  • Breaking the current validator out into a subclass, acting as the foundation for supporting multiple versions of validators

json-schema's People

Contributors

hoxworth avatar

Stargazers

 avatar  avatar

Watchers

 avatar  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.