hjsonschema: JSON Schema Draft 4 library

[ data, deprecated, library, mit ] [ Propose Tags ]
Deprecated

Downloads

Maintainer's Corner

Package maintainers

For package maintainers and hackage trustees

Candidates

  • No Candidates
Versions [RSS] 0.1.0.0, 0.1.1.0, 0.2.0.0, 0.3.0.0, 0.4.0.0, 0.5.0.0, 0.5.1.0, 0.5.1.1, 0.5.1.2, 0.5.1.3, 0.5.2.0, 0.5.2.1, 0.5.2.2, 0.5.3.0, 0.5.3.1, 0.5.3.2, 0.6.0.0, 0.6.0.1, 0.6.0.2, 0.7.0.0, 0.7.1.0, 0.8.0.0, 0.8.0.1, 0.9.0.0, 0.10.0.0, 0.10.0.1, 0.10.0.2, 0.10.0.3, 1.0.0.0, 1.1.0.0, 1.1.0.1, 1.2.0.0, 1.2.0.1, 1.2.0.2, 1.3.0.0, 1.3.0.1, 1.4.0.0, 1.5.0.0, 1.5.0.1, 1.6.0, 1.6.1, 1.6.2, 1.6.3, 1.7.0, 1.7.1, 1.7.2, 1.8.0, 1.9.0, 1.10.0 (info)
Change log changelog.txt
Dependencies aeson (>=0.7 && <0.10), base (>=4.6 && <4.9), bytestring (>=0.10 && <0.11), file-embed (>=0.0.8 && <0.0.9), hashable (>=1.2 && <1.3), hjsonpointer (>=0.2 && <0.3), http-client (>=0.4.9 && <0.5), http-types (>=0.8 && <0.9), regexpr (>=0.5 && <0.6), scientific (>=0.3 && <0.4), text (>=1.2 && <1.3), unordered-containers (>=0.2 && <0.3), vector (>=0.10 && <0.11) [details]
License MIT
Author Ian Grant Jeffries
Maintainer ian@housejeffries.com
Category Data
Home page https://github.com/seagreen/hjsonschema
Source repo head: git clone git://github.com/seagreen/hjsonschema.git
Uploaded by seagreen at 2015-07-12T17:03:30Z
Distributions
Reverse Dependencies 6 direct, 1 indirect [details]
Downloads 32413 total (151 in the last 30 days)
Rating (no votes yet) [estimated by Bayesian average]
Your Rating
  • λ
  • λ
  • λ
Status Docs available [build log]
Last success reported on 2015-07-12 [all 1 reports]

Readme for hjsonschema-0.6.0.1

[back to package description]

Intro

An implementation of JSON Schema Draft 4 in haskell.

Status

Still in development. Lacks solid code to handle changing resolution scope.

Example

{-# LANGUAGE OverloadedStrings #-}

module Main where

import Data.Aeson
import qualified Data.HashMap.Strict as H
import qualified Data.JsonSchema as JS
import qualified Data.Vector as V

main :: IO ()
main = do
  eitherGraph <- JS.fetchRefs JS.draft4 rawSchema H.empty
  case eitherGraph of
    Left e      -> print e
    Right graph ->
      case JS.compileDraft4 graph rawSchema of
        Left e2      -> print e2
        Right schema -> print $ JS.validate schema invalidData

rawSchema :: JS.RawSchema
rawSchema = JS.RawSchema
  { JS._rsURI = ""
  , JS._rsObject = H.singleton "uniqueItems" (Bool True) -- Schema JSON goes here.
  }

invalidData :: Value
invalidData = Array (V.fromList ["foo", "foo"])

Output:

Left (fromList ["Val error against uniqueItems True for: Array (fromList [String \"foo\",String \"foo\"])"])

Install Tests

git submodule update --init

Notes

  • This uses the regexpr regular expression library for the "pattern" validator. I have no idea if this is compatible with the ECMA 262 regex dialect, which the spec requires.

  • draft4.json is from commit # cc8ec81ce0abe2385ebd6c2a6f2d6deb646f874a here.

Credits

Thanks to Julian Berman for the fantastic test suite.

Also thanks to Tim Baumann for his aeson-schema library. Hjsonschema's test code and its implementation of Graph both come from Aeson-Schema.