<commit_before># Intro

An implementation of [JSON Schema](http://json-schema.org/) Draft 4 in haskell.

# Status

Still in development. Lacks solid code to fetch remote schemas.

# 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 g ->
      case JS.compileDraft4 g rawSchema of
        Left e2 -> print e2
        Right a -> print $ JS.validate a 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:
```
fromList ["Val error against uniqueItems True for: Array (fromList [String \"foo\",String \"foo\"])"]
```


# Install Tests

    git submodule update --init

# Run Tests

    cd JSON-Schema-Test-Suite/remotes
    hserv --port=1234 (or python -m SimpleHTTPServer 1234)

Then run the normal `cabal test` from another terminal.

Note that the tests require an internet connection.

# Notes

+ This uses the [regexpr](https://hackage.haskell.org/package/regexpr-0.5.4) regular expression library fo the "pattern" validator. I have no idea if this is compatible with the ECMA 262 regex dialect, which the [spec](http://json-schema.org/latest/json-schema-validation.html#anchor33) requires.

+ `draft4.json` is from commit # cc8ec81ce0abe2385ebd6c2a6f2d6deb646f874a [here](https://github.com/json-schema/json-schema).

# Credits

Thanks to [<NAME>](https://github.com/Julian) for the fantastic test suite.

Also thanks to <NAME> for his [aeson-schema](https://hackage.haskell.org/package/aeson-schema) library. Hjsonschema's test code and its implementation of `Graph` both come from Aeson-Schema.<commit_msg>Touch up README.<commit_after># Intro

An implementation of [JSON Schema](http://json-schema.org/) Draft 4 in haskell.

# Status

Still in development. Lacks solid code to fetch remote schemas.

# 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:
```
fromList ["Val error against uniqueItems True for: Array (fromList [String \"foo\",String \"foo\"])"]
```


# Install Tests

    git submodule update --init

# Prepare Tests

+ `cd JSON-Schema-Test-Suite/remotes

+ `hserv --port=1234` / `python -m SimpleHTTPServer 1234`

Note that the `remote` test suite requires an internet connection.

# Notes

+ This uses the [regexpr](https://hackage.haskell.org/package/regexpr-0.5.4) regular expression library fo the "pattern" validator. I have no idea if this is compatible with the ECMA 262 regex dialect, which the [spec](http://json-schema.org/latest/json-schema-validation.html#anchor33) requires.

+ `draft4.json` is from commit # cc8ec81ce0abe2385ebd6c2a6f2d6deb646f874a [here](https://github.com/json-schema/json-schema).

# Credits

Thanks to [<NAME>](https://github.com/Julian) for the fantastic test suite.

Also thanks to <NAME> for his [aeson-schema](https://hackage.haskell.org/package/aeson-schema) library. Hjsonschema's test code and its implementation of `Graph` both come from Aeson-Schema.
{'fraction_non_alphanumeric': 0.11336844745422624, 'fraction_numerical': 0.02056684223727113, 'mean_word_length': 3.793269230769231, 'pattern_counts': {'":': 0, '<': 9, '<?xml version=': 0, '>': 15, 'https://': 8, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '841933', 'n_tokens_mistral': 1319, 'n_tokens_neox': 1241, 'n_words': 415}