All Projects → davishmcclurg → Json_schemer

davishmcclurg / Json_schemer

Licence: mit
JSON Schema validator. Supports drafts 4, 6, and 7.

Programming Languages

ruby
36898 projects - #4 most used programming language

Projects that are alternatives of or similar to Json schemer

Jsonschema2db
Generate tables dynamically from a JSON Schema and insert data
Stars: ✭ 152 (-23.62%)
Mutual labels:  json-schema
Newtonsoft.json.schema
Json.NET Schema is a powerful, complete and easy to use JSON Schema framework for .NET
Stars: ✭ 167 (-16.08%)
Mutual labels:  json-schema
Ajv Errors
Custom error messages in JSON-Schema for Ajv
Stars: ✭ 185 (-7.04%)
Mutual labels:  json-schema
Cfworker
A collection of packages optimized for Cloudflare Workers and service workers.
Stars: ✭ 152 (-23.62%)
Mutual labels:  json-schema
Go Jsonschema
A tool to generate Go data types from JSON Schema definitions.
Stars: ✭ 164 (-17.59%)
Mutual labels:  json-schema
Marshmallow Jsonschema
JSON Schema Draft v7 (http://json-schema.org/) formatting with marshmallow
Stars: ✭ 172 (-13.57%)
Mutual labels:  json-schema
Json Schema Viewer
JavaScript tool for visualizing json-schemas
Stars: ✭ 147 (-26.13%)
Mutual labels:  json-schema
Json Schema Editor
JSON Schema Editor is an intuitive editor for JSON schema. It provides a tree view to present the structure of schema, and a property inspector to edit the properties of schema element. Develop with Vue.js 2 and Firebase.
Stars: ✭ 194 (-2.51%)
Mutual labels:  json-schema
Liform React
Generate forms from JSON Schema to use with React (& redux-form)
Stars: ✭ 167 (-16.08%)
Mutual labels:  json-schema
Json Guard
Validation of json-schema.org compliant schemas.
Stars: ✭ 184 (-7.54%)
Mutual labels:  json-schema
Ngx Formly
JSON powered / Dynamic forms for Angular
Stars: ✭ 2,109 (+959.8%)
Mutual labels:  json-schema
Xdm
Experience Data Model
Stars: ✭ 160 (-19.6%)
Mutual labels:  json-schema
Staticjson
Fast, direct and static typed parsing of JSON with C++
Stars: ✭ 177 (-11.06%)
Mutual labels:  json-schema
Skillset
✨ Intuitive job-candidate skill visualization, taking advantage of D3.js and JSONResume.
Stars: ✭ 152 (-23.62%)
Mutual labels:  json-schema
Ajv Keywords
Custom JSON-Schema keywords for Ajv validator
Stars: ✭ 186 (-6.53%)
Mutual labels:  json-schema
Ajv Cli
Use 'Another Json Validator' (ajv) from the command line
Stars: ✭ 148 (-25.63%)
Mutual labels:  json-schema
Json Schema To Openapi Schema
A little NodeJS package to convert JSON Schema to OpenAPI Schema Objects
Stars: ✭ 168 (-15.58%)
Mutual labels:  json-schema
Jsonform
Build forms from JSON Schema. Easily template-able. Compatible with Bootstrap 3 out of the box.
Stars: ✭ 2,416 (+1114.07%)
Mutual labels:  json-schema
Json Schema Spec
The JSON Schema I-D sources
Stars: ✭ 2,441 (+1126.63%)
Mutual labels:  json-schema
Schemars
Generate JSON Schema documents from Rust code
Stars: ✭ 181 (-9.05%)
Mutual labels:  json-schema

JSONSchemer

JSON Schema validator. Supports drafts 4, 6, and 7.

Installation

Add this line to your application's Gemfile:

gem 'json_schemer'

And then execute:

$ bundle

Or install it yourself as:

$ gem install json_schemer

Usage

require 'json_schemer'

schema = {
  'type' => 'object',
  'properties' => {
    'abc' => {
      'type' => 'integer',
      'minimum' => 11
    }
  }
}
schemer = JSONSchemer.schema(schema)

# true/false validation

schemer.valid?({ 'abc' => 11 })
# => true

schemer.valid?({ 'abc' => 10 })
# => false

# error validation (`validate` returns an enumerator)

schemer.validate({ 'abc' => 10 }).to_a
# => [{"data"=>10, "schema"=>{"type"=>"integer", "minimum"=>11}, "pointer"=>"#/abc", "type"=>"minimum"}]

# default property values

data = {}
JSONSchemer.schema(
  {
    'properties' => {
      'foo' => {
        'default' => 'bar'
      }
    }
  },
  insert_property_defaults: true
).valid?(data)
data
# => {"foo"=>"bar"}

# schema files

require 'pathname'

schema = Pathname.new('/path/to/schema.json')
schemer = JSONSchemer.schema(schema)

# schema json string

schema = '{ "type": "integer" }'
schemer = JSONSchemer.schema(schema)

Options

JSONSchemer.schema(
  schema,

  # validate `format` (https://tools.ietf.org/html/draft-handrews-json-schema-validation-00#section-7)
  # true/false
  # default: true
  format: true,

  # insert default property values during validation
  # true/false
  # default: false
  insert_property_defaults: true,

  # modify properties during validation. You can pass one Proc or a list of Procs to modify data.
  # Proc/[Proc]
  # default: nil
  before_property_validation: proc do |data, property, property_schema, _parent|
    data[property] ||= 42
  end,

  # modify properties after validation. You can pass one Proc or a list of Procs to modify data.
  # Proc/[Proc]
  # default: nil
  after_property_validation: proc do |data, property, property_schema, _parent|
    data[property] = Date.iso8601(data[property]) if property_schema.is_a?(Hash) && property_schema['format'] == 'date'
  end,

  # resolve external references
  # 'net/http'/proc/lambda/respond_to?(:call)
  # 'net/http': proc { |uri| JSON.parse(Net::HTTP.get(uri)) }
  # default: proc { |uri| raise UnknownRef, uri.to_s }
  ref_resolver: 'net/http'
)

Development

After checking out the repo, run bin/setup to install dependencies. Then, run rake test to run the tests. You can also run bin/console for an interactive prompt that will allow you to experiment.

Build Status

Build Status

Contributing

Bug reports and pull requests are welcome on GitHub at https://github.com/davishmcclurg/json_schemer.

License

The gem is available as open source under the terms of the MIT License.

Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].