Class: JsonSchema

Inherits:
Object
  • Object
show all
Defined in:
lib/json_schema.rb

Overview

Copyright © 2009-2011 VMware, Inc. This class provides dead simple declarative validation for decoded json using a fairly intuitive DSL like syntax.

For example, the following is a sample schema that exercises all functionality

{‘foo’ => [String], # ‘foo’ must be a list of strings

'bar' => {'baz' => Fixnum,    # 'bar' must be a hash where
          'jaz' => /foo/,     #   'baz' is a Fixnum, and
         }                    #   'jaz' matches the regex /foo/

}

Constant Summary collapse

WILDCARD =
Object

Instance Method Summary collapse

Constructor Details

#initialize(schema) ⇒ JsonSchema

TODO(mjp): validate that schema is syntatically correct



18
19
20
# File 'lib/json_schema.rb', line 18

def initialize(schema)
  @schema = schema
end

Instance Method Details

#validate(json) ⇒ Object



22
23
24
# File 'lib/json_schema.rb', line 22

def validate(json)
  _validate(json, @schema)
end