packages feed

hjsonschema-0.5.2.0: Main.hs

{-# 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"])