module Data.Aeson.Extras (
JsonError(..)
) where
import Data.Aeson
( Value() )
import Data.ByteString.Lazy
( ByteString )
import Data.String
( fromString )
import Data.Text
( Text )
import Test.QuickCheck
( Arbitrary(..), Gen )
data JsonError
= JsonError String
| JsonParseError ByteString
| JsonKeyDoesNotExist Text Value
| JsonKeyLookupOffObject Text Value
| JsonConstructError String
deriving (Eq, Show)
instance Arbitrary JsonError where
arbitrary = do
k <- arbitrary :: Gen Int
case k `mod` 5 of
0 -> JsonError <$> arbitrary
1 -> JsonParseError <$> (fromString <$> arbitrary)
2 -> JsonKeyDoesNotExist <$>
(fromString <$> arbitrary) <*>
(fromString <$> arbitrary)
3 -> JsonKeyLookupOffObject <$>
(fromString <$> arbitrary) <*>
(fromString <$> arbitrary)
_ -> JsonConstructError <$> arbitrary