Git Product home page Git Product logo

json_schema.cr's Introduction

json_schema

An attempt to implement json schema validation in Crystal.

Work in progress but could be a useful start

Installation

  1. Add the dependency to your shard.yml:

    dependencies:
      json_schema:
        github: kefahi/json_schema.cr
  2. Run shards install

Usage

Sample data.json

{
    "id": 1,
    "name": "A green door",
    "price": 12.50,
    "tags": ["home", "green"]
}

Sample schema.json

{
    "$schema": "http://json-schema.org/draft-04/schema#",
    "title": "Product",
    "description": "A product from Acme's catalog",
    "type": "object",
    "properties": {
      "id": {
          "description": "The unique identifier for a product",
          "type": "integer"
      },
      "name": {
          "description": "The unique identifier for a product",
          "type": "string"
      },
      "price": {
          "type": "number",
          "minimum": 0,
          "exclusiveMinimum": true
      },
      "dimensions": {
          "type": "object",
          "properties": {
              "length": {"type": "number"},
              "width": {"type": "number"},
              "height": {"type": "number"}
          },
          "required": ["length", "width", "height"]
      }
			
    },
    "required": ["id"]
}

Sample code

require "json_schema"
json_data = JSON.parse File.read "data.json" 
schema = JSON::Schema.from_json File.read "schema.json"
schema.validate json_data

Contributing

  1. Fork it (https://github.com/kefahi/json_schema.cr/fork)
  2. Create your feature branch (git checkout -b my-new-feature)
  3. Commit your changes (git commit -am 'Add some feature')
  4. Push to the branch (git push origin my-new-feature)
  5. Create a new Pull Request

Contributors

json_schema.cr's People

Contributors

dougeverly avatar kefahi avatar

Stargazers

Margret Riegert avatar Juri Hahn avatar baxiry avatar Vlad Zarakovsky avatar Elliot DeNolf avatar Gregory Loscombe avatar Alexander ADAM avatar Johano R. Sulfuro 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.