aeson-extra-0.4.0.0: Extra goodies for aeson

Copyright | (C) 2015-2016 Oleg Grenrus
License | BSD3
Maintainer | Oleg Grenrus <oleg.grenrus@iki.fi>
Safe Haskell | None
Language | Haskell2010

Data.Aeson.Extra

Contents

- Strict encoding
- Generic maps
- Symbol tag
- Singleton object
- CollapsedList
- UTCTime
- Algebra
- Merge
- Stream
- Template Haskell
- Re-exports

Description

More or less useful newtypes for writing `FromJSON` & `ToJSON` instances

Synopsis

- encodeStrict :: ToJSON a => a -> ByteString
- newtype M a = M {
  - getMap :: a
  }
- class FromJSONKey a where
- parseIntegralJSONKey :: Integral a => Text -> Parser a
- class FromJSONMap m k v | m -> k v where
- class ToJSONKey a where
- class ToJSONMap m k v | m -> k v where
- data SymTag s = SymTag
- newtype SingObject s a = SingObject a
- mkSingObject :: Proxy s -> a -> SingObject s a
- getSingObject :: Proxy s -> SingObject s a -> a
- newtype CollapsedList f a = CollapsedList (f a)
- getCollapsedList :: CollapsedList f a -> f a
- parseCollapsedList :: (FromJSON a, FromJSON1 f, Alternative f) => Object -> Text -> Parser (f a)
- newtype U = U {
  - getU :: UTCTime
  }
- newtype Z = Z {
  - getZ :: ZonedTime
  }
- data ValueF a
  - = ObjectF (ObjectF a)
  - | ArrayF !(ArrayF a)
  - | StringF !Text
  - | NumberF !Scientific
  - | BoolF !Bool
  - | NullF
- type ObjectF a = HashMap Text a
- type ArrayF a = Vector a
- merge :: (forall a. (a -> a -> a) -> ValueF a -> ValueF a -> ValueF a) -> Value -> Value -> Value
- streamDecode :: forall a. FromJSON a => ByteString -> ([a], Maybe String)
- mkValue :: String -> Q Exp
- mkValue' :: String -> Q Exp
- module Data.Aeson.Compat

# Strict encoding

encodeStrict :: ToJSON a => a -> ByteString Source #

Like `encode`, but produces strict `ByteString`.

Since: 0.2.3.0

# Generic maps

newtype M a Source #

A wrapper type to parse arbitrary maps

    λ > decode "{\"1\": 1, \"2\": 2}" :: Maybe (M (H.HashMap Int Int))
    Just (M {getMap = fromList [(1,1),(2,2)]})

Constructors

M |

Fields

- getMap :: a

Instances

Functor M Source # |
Methods fmap :: (a -> b) -> M a -> M b # (<$) :: a -> M b -> M a #
Foldable M Source # |

Methods

fold :: Monoid m => M m -> m #

foldMap :: Monoid m => (a -> m) -> M a -> m #

foldr :: (a -> b -> b) -> b -> M a -> b #

foldr' :: (a -> b -> b) -> b -> M a -> b #

foldl :: (b -> a -> b) -> b -> M a -> b #

foldl' :: (b -> a -> b) -> b -> M a -> b #

foldr1 :: (a -> a -> a) -> M a -> a #

foldl1 :: (a -> a -> a) -> M a -> a #

toList :: M a -> [a] #

null :: M a -> Bool #

length :: M a -> Int #

elem :: Eq a => a -> M a -> Bool #

maximum :: Ord a => M a -> a #

minimum :: Ord a => M a -> a #

sum :: Num a => M a -> a #

product :: Num a => M a -> a #

Traversable M Source # |
Methods traverse :: Applicative f => (a -> f b) -> M a -> f (M b) # sequenceA :: Applicative f => M (f a) -> f (M a) # mapM :: Monad m => (a -> m b) -> M a -> m (M b) # sequence :: Monad m => M (m a) -> m (M a) #
Eq a => Eq (M a) Source # |
Methods (==) :: M a -> M a -> Bool # (/=) :: M a -> M a -> Bool #
Ord a => Ord (M a) Source # |
Methods compare :: M a -> M a -> Ordering # (<) :: M a -> M a -> Bool # (<=) :: M a -> M a -> Bool # (>) :: M a -> M a -> Bool # (>=) :: M a -> M a -> Bool # max :: M a -> M a -> M a # min :: M a -> M a -> M a #
Read a => Read (M a) Source # |
Methods readsPrec :: Int -> ReadS (M a) # readList :: ReadS [M a] # readPrec :: ReadPrec (M a) # readListPrec :: ReadPrec [M a] #
Show a => Show (M a) Source # |
Methods showsPrec :: Int -> M a -> ShowS # show :: M a -> String # showList :: [M a] -> ShowS #
ToJSONMap m k v => ToJSON (M m) Source # |
Methods toJSON :: M m -> Value # toEncoding :: M m -> Encoding # toJSONList :: [M m] -> Value # toEncodingList :: [M m] -> Encoding #
FromJSONMap m k v => FromJSON (M m) Source # |
Methods parseJSON :: Value -> Parser (M m) # parseJSONList :: Value -> Parser [M m] #

class FromJSONKey a where Source #

Minimal complete definition

parseJSONKey

Methods

parseJSONKey :: Text -> Parser a Source #

Instances

FromJSONKey Int Source # |
Methods parseJSONKey :: Text -> Parser Int Source #
FromJSONKey Integer Source # |
Methods parseJSONKey :: Text -> Parser Integer Source #
FromJSONKey String Source # |
Methods parseJSONKey :: Text -> Parser String Source #
FromJSONKey Text Source # |
Methods parseJSONKey :: Text -> Parser Text Source #
FromJSONKey Text Source # |
Methods parseJSONKey :: Text -> Parser Text Source #

parseIntegralJSONKey :: Integral a => Text -> Parser a Source #

class FromJSONMap m k v | m -> k v where Source #

Minimal complete definition

parseJSONMap

Methods

parseJSONMap :: HashMap Text Value -> Parser m Source #

Instances

(Eq k, Hashable k, FromJSONKey k, FromJSON v) => FromJSONMap (HashMap k v) k v Source # |
Methods parseJSONMap :: HashMap Text Value -> Parser (HashMap k v) Source #
(Ord k, FromJSONKey k, FromJSON v) => FromJSONMap (Map k v) k v Source # |
Methods parseJSONMap :: HashMap Text Value -> Parser (Map k v) Source #

class ToJSONKey a where Source #

Minimal complete definition

toJSONKey

Methods

toJSONKey :: a -> Text Source #

Instances

ToJSONKey Int Source # |
Methods toJSONKey :: Int -> Text Source #
ToJSONKey Integer Source # |
Methods toJSONKey :: Integer -> Text Source #
ToJSONKey String Source # |
Methods toJSONKey :: String -> Text Source #
ToJSONKey Text Source # |
Methods toJSONKey :: Text -> Text Source #
ToJSONKey Text Source # |
Methods toJSONKey :: Text -> Text Source #

class ToJSONMap m k v | m -> k v where Source #

Minimal complete definition

toJSONMap

Methods

toJSONMap :: m -> HashMap Text Value Source #

Instances

(ToJSONKey k, ToJSON v) => ToJSONMap (HashMap k v) k v Source # |
Methods toJSONMap :: HashMap k v -> HashMap Text Value Source #
(ToJSONKey k, ToJSON v) => ToJSONMap (Map k v) k v Source # |
Methods toJSONMap :: Map k v -> HashMap Text Value Source #

# Symbol tag

data SymTag s Source #

Singleton string encoded and decoded as ifself.

    λ> encode (SymTag :: SymTag "foobar")
    "\"foobar\""

    decode "\"foobar\"" :: Maybe (SymTag "foobar")
    Just SymTag

    decode "\"foobar\"" :: Maybe (SymTag "barfoo")
    Nothing

Available with: base >=4.7

Constructors

SymTag |

Instances

Bounded (SymTag s) Source # |
Methods minBound :: SymTag s # maxBound :: SymTag s #
Enum (SymTag s) Source # |
Methods succ :: SymTag s -> SymTag s # pred :: SymTag s -> SymTag s # toEnum :: Int -> SymTag s # fromEnum :: SymTag s -> Int # enumFrom :: SymTag s -> [SymTag s] # enumFromThen :: SymTag s -> SymTag s -> [SymTag s] # enumFromTo :: SymTag s -> SymTag s -> [SymTag s] # enumFromThenTo :: SymTag s -> SymTag s -> SymTag s -> [SymTag s] #
Eq (SymTag s) Source # |
Methods (==) :: SymTag s -> SymTag s -> Bool # (/=) :: SymTag s -> SymTag s -> Bool #
Ord (SymTag s) Source # |
Methods compare :: SymTag s -> SymTag s -> Ordering # (<) :: SymTag s -> SymTag s -> Bool # (<=) :: SymTag s -> SymTag s -> Bool # (>) :: SymTag s -> SymTag s -> Bool # (>=) :: SymTag s -> SymTag s -> Bool # max :: SymTag s -> SymTag s -> SymTag s # min :: SymTag s -> SymTag s -> SymTag s #
Read (SymTag s) Source # |
Methods readsPrec :: Int -> ReadS (SymTag s) # readList :: ReadS [SymTag s] # readPrec :: ReadPrec (SymTag s) # readListPrec :: ReadPrec [SymTag s] #
Show (SymTag s) Source # |
Methods showsPrec :: Int -> SymTag s -> ShowS # show :: SymTag s -> String # showList :: [SymTag s] -> ShowS #
KnownSymbol s => ToJSON (SymTag s) Source # |
Methods toJSON :: SymTag s -> Value # toEncoding :: SymTag s -> Encoding # toJSONList :: [SymTag s] -> Value # toEncodingList :: [SymTag s] -> Encoding #
KnownSymbol s => FromJSON (SymTag s) Source # |
Methods parseJSON :: Value -> Parser (SymTag s) # parseJSONList :: Value -> Parser [SymTag s] #

# Singleton object

newtype SingObject s a Source #

Singleton value object

    λ > decode "{\"value\": 42 }" :: Maybe (SingObject "value" Int)
    Just (SingObject 42)

    λ > encode (SingObject 42 :: SingObject "value" Int)
    "{\"value\":42}"

Available with: base >=4.7

Constructors

SingObject a |

Instances

Functor (SingObject s) Source # |
Methods fmap :: (a -> b) -> SingObject s a -> SingObject s b # (<$) :: a -> SingObject s b -> SingObject s a #
Foldable (SingObject s) Source # |

Methods

fold :: Monoid m => SingObject s m -> m #

foldMap :: Monoid m => (a -> m) -> SingObject s a -> m #

foldr :: (a -> b -> b) -> b -> SingObject s a -> b #

foldr' :: (a -> b -> b) -> b -> SingObject s a -> b #

foldl :: (b -> a -> b) -> b -> SingObject s a -> b #

foldl' :: (b -> a -> b) -> b -> SingObject s a -> b #

foldr1 :: (a -> a -> a) -> SingObject s a -> a #

foldl1 :: (a -> a -> a) -> SingObject s a -> a #

toList :: SingObject s a -> [a] #

null :: SingObject s a -> Bool #

length :: SingObject s a -> Int #

elem :: Eq a => a -> SingObject s a -> Bool #

maximum :: Ord a => SingObject s a -> a #

minimum :: Ord a => SingObject s a -> a #

sum :: Num a => SingObject s a -> a #

product :: Num a => SingObject s a -> a #

Traversable (SingObject s) Source # |
Methods traverse :: Applicative f => (a -> f b) -> SingObject s a -> f (SingObject s b) # sequenceA :: Applicative f => SingObject s (f a) -> f (SingObject s a) # mapM :: Monad m => (a -> m b) -> SingObject s a -> m (SingObject s b) # sequence :: Monad m => SingObject s (m a) -> m (SingObject s a) #
KnownSymbol s => ToJSON1 (SingObject s) Source # |
Methods liftToJSON :: (a -> Value) -> ([a] -> Value) -> SingObject s a -> Value # liftToJSONList :: (a -> Value) -> ([a] -> Value) -> [SingObject s a] -> Value # liftToEncoding :: (a -> Encoding) -> ([a] -> Encoding) -> SingObject s a -> Encoding # liftToEncodingList :: (a -> Encoding) -> ([a] -> Encoding) -> [SingObject s a] -> Encoding #
KnownSymbol s => FromJSON1 (SingObject s) Source # |
Methods liftParseJSON :: (Value -> Parser a) -> (Value -> Parser [a]) -> Value -> Parser (SingObject s a) # liftParseJSONList :: (Value -> Parser a) -> (Value -> Parser [a]) -> Value -> Parser [SingObject s a] #
Eq a => Eq (SingObject s a) Source # |
Methods (==) :: SingObject s a -> SingObject s a -> Bool # (/=) :: SingObject s a -> SingObject s a -> Bool #
Ord a => Ord (SingObject s a) Source # |
Methods compare :: SingObject s a -> SingObject s a -> Ordering # (<) :: SingObject s a -> SingObject s a -> Bool # (<=) :: SingObject s a -> SingObject s a -> Bool # (>) :: SingObject s a -> SingObject s a -> Bool # (>=) :: SingObject s a -> SingObject s a -> Bool # max :: SingObject s a -> SingObject s a -> SingObject s a # min :: SingObject s a -> SingObject s a -> SingObject s a #
Read a => Read (SingObject s a) Source # |
Methods readsPrec :: Int -> ReadS (SingObject s a) # readList :: ReadS [SingObject s a] # readPrec :: ReadPrec (SingObject s a) # readListPrec :: ReadPrec [SingObject s a] #
Show a => Show (SingObject s a) Source # |
Methods showsPrec :: Int -> SingObject s a -> ShowS # show :: SingObject s a -> String # showList :: [SingObject s a] -> ShowS #
(KnownSymbol s, ToJSON a) => ToJSON (SingObject s a) Source # |
Methods toJSON :: SingObject s a -> Value # toEncoding :: SingObject s a -> Encoding # toJSONList :: [SingObject s a] -> Value # toEncodingList :: [SingObject s a] -> Encoding #
(KnownSymbol s, FromJSON a) => FromJSON (SingObject s a) Source # |
Methods parseJSON :: Value -> Parser (SingObject s a) # parseJSONList :: Value -> Parser [SingObject s a] #

mkSingObject :: Proxy s -> a -> SingObject s a Source #

getSingObject :: Proxy s -> SingObject s a -> a Source #

# CollapsedList

newtype CollapsedList f a Source #

Collapsed list, singleton is represented as the value itself in JSON encoding.

    λ > decode "null" :: Maybe (CollapsedList [Int] Int)
    Just (CollapsedList [])
    λ > decode "42" :: Maybe (CollapsedList [Int] Int)
    Just (CollapsedList [42])
    λ > decode "[1, 2, 3]" :: Maybe (CollapsedList [Int] Int)
    Just (CollapsedList [1,2,3])

    λ > encode (CollapsedList ([] :: [Int]))
    "null"
    λ > encode (CollapsedList ([42] :: [Int]))
    "42"
    λ > encode (CollapsedList ([1, 2, 3] :: [Int]))
    "[1,2,3]"

Documentation rely on `f` `Alternative` instance behaving like lists'.

Constructors

CollapsedList (f a) |

Instances

Functor f => Functor (CollapsedList f) Source # |
Methods fmap :: (a -> b) -> CollapsedList f a -> CollapsedList f b # (<$) :: a -> CollapsedList f b -> CollapsedList f a #
Foldable f => Foldable (CollapsedList f) Source # |

Methods

fold :: Monoid m => CollapsedList f m -> m #

foldMap :: Monoid m => (a -> m) -> CollapsedList f a -> m #

foldr :: (a -> b -> b) -> b -> CollapsedList f a -> b #

foldr' :: (a -> b -> b) -> b -> CollapsedList f a -> b #

foldl :: (b -> a -> b) -> b -> CollapsedList f a -> b #

foldl' :: (b -> a -> b) -> b -> CollapsedList f a -> b #

foldr1 :: (a -> a -> a) -> CollapsedList f a -> a #

foldl1 :: (a -> a -> a) -> CollapsedList f a -> a #

toList :: CollapsedList f a -> [a] #

null :: CollapsedList f a -> Bool #

length :: CollapsedList f a -> Int #

elem :: Eq a => a -> CollapsedList f a -> Bool #

maximum :: Ord a => CollapsedList f a -> a #

minimum :: Ord a => CollapsedList f a -> a #

sum :: Num a => CollapsedList f a -> a #

product :: Num a => CollapsedList f a -> a #

Traversable f => Traversable (CollapsedList f) Source # |
Methods traverse :: Applicative f => (a -> f b) -> CollapsedList f a -> f (CollapsedList f b) # sequenceA :: Applicative f => CollapsedList f (f a) -> f (CollapsedList f a) # mapM :: Monad m => (a -> m b) -> CollapsedList f a -> m (CollapsedList f b) # sequence :: Monad m => CollapsedList f (m a) -> m (CollapsedList f a) #
(ToJSON1 f, Foldable f) => ToJSON1 (CollapsedList f) Source # |
Methods liftToJSON :: (a -> Value) -> ([a] -> Value) -> CollapsedList f a -> Value # liftToJSONList :: (a -> Value) -> ([a] -> Value) -> [CollapsedList f a] -> Value # liftToEncoding :: (a -> Encoding) -> ([a] -> Encoding) -> CollapsedList f a -> Encoding # liftToEncodingList :: (a -> Encoding) -> ([a] -> Encoding) -> [CollapsedList f a] -> Encoding #
(FromJSON1 f, Alternative f) => FromJSON1 (CollapsedList f) Source # |
Methods liftParseJSON :: (Value -> Parser a) -> (Value -> Parser [a]) -> Value -> Parser (CollapsedList f a) # liftParseJSONList :: (Value -> Parser a) -> (Value -> Parser [a]) -> Value -> Parser [CollapsedList f a] #
Eq (f a) => Eq (CollapsedList f a) Source # |
Methods (==) :: CollapsedList f a -> CollapsedList f a -> Bool # (/=) :: CollapsedList f a -> CollapsedList f a -> Bool #
Ord (f a) => Ord (CollapsedList f a) Source # |

Methods

compare :: CollapsedList f a -> CollapsedList f a -> Ordering #

(<) :: CollapsedList f a -> CollapsedList f a -> Bool #

(<=) :: CollapsedList f a -> CollapsedList f a -> Bool #

(>) :: CollapsedList f a -> CollapsedList f a -> Bool #

(>=) :: CollapsedList f a -> CollapsedList f a -> Bool #

max :: CollapsedList f a -> CollapsedList f a -> CollapsedList f a #

min :: CollapsedList f a -> CollapsedList f a -> CollapsedList f a #

Read (f a) => Read (CollapsedList f a) Source # |
Methods readsPrec :: Int -> ReadS (CollapsedList f a) # readList :: ReadS [CollapsedList f a] # readPrec :: ReadPrec (CollapsedList f a) # readListPrec :: ReadPrec [CollapsedList f a] #
Show (f a) => Show (CollapsedList f a) Source # |
Methods showsPrec :: Int -> CollapsedList f a -> ShowS # show :: CollapsedList f a -> String # showList :: [CollapsedList f a] -> ShowS #
(ToJSON1 f, Foldable f, ToJSON a) => ToJSON (CollapsedList f a) Source # |
Methods toJSON :: CollapsedList f a -> Value # toEncoding :: CollapsedList f a -> Encoding # toJSONList :: [CollapsedList f a] -> Value # toEncodingList :: [CollapsedList f a] -> Encoding #
(FromJSON1 f, Alternative f, FromJSON a) => FromJSON (CollapsedList f a) Source # |
Methods parseJSON :: Value -> Parser (CollapsedList f a) # parseJSONList :: Value -> Parser [CollapsedList f a] #

getCollapsedList :: CollapsedList f a -> f a Source #

parseCollapsedList :: (FromJSON a, FromJSON1 f, Alternative f) => Object -> Text -> Parser (f a) Source #

Parses possibly collapsed array value from the object's field.

    λ > newtype V = V [Int] deriving (Show)
    λ > instance FromJSON V where parseJSON = withObject "V" $ \obj -> V <$> parseCollapsedList obj "value"
    λ > decode "{}" :: Maybe V
    Just (V [])
    λ > decode "{\"value\": null}" :: Maybe V
    Just (V [])
    λ > decode "{\"value\": 42}" :: Maybe V
    Just (V [42])
    λ > decode "{\"value\": [1, 2, 3, 4]}" :: Maybe V
    Just (V [1,2,3,4])

# UTCTime

newtype U Source #

A type to parse `UTCTime`

`FromJSON` instance accepts for example:

    2015-09-07T08:16:40.807Z
    2015-09-07 11:16:40.807 +03:00

Latter format is accepted by `aeson` staring from version `0.10.0.0`.

See https://github.com/bos/aeson/blob/4667ef1029a373cf4510f7deca147c357c6d8947/Data/Aeson/Parser/Time.hs#L150

Since: aeson-extra-0.2.2.0

Constructors

U |

Fields

- getU :: UTCTime

Instances

Eq U Source # |
Methods (==) :: U -> U -> Bool # (/=) :: U -> U -> Bool #
Ord U Source # |
Methods compare :: U -> U -> Ordering # (<) :: U -> U -> Bool # (<=) :: U -> U -> Bool # (>) :: U -> U -> Bool # (>=) :: U -> U -> Bool # max :: U -> U -> U # min :: U -> U -> U #
Read U Source # |
Methods readsPrec :: Int -> ReadS U # readList :: ReadS [U] # readPrec :: ReadPrec U # readListPrec :: ReadPrec [U] #
Show U Source # |
Methods showsPrec :: Int -> U -> ShowS # show :: U -> String # showList :: [U] -> ShowS #
ToJSON U Source # |
Methods toJSON :: U -> Value # toEncoding :: U -> Encoding # toJSONList :: [U] -> Value # toEncodingList :: [U] -> Encoding #
FromJSON U Source # |
Methods parseJSON :: Value -> Parser U # parseJSONList :: Value -> Parser [U] #

newtype Z Source #

A type to parse `ZonedTime`

Since: aeson-extra-0.2.2.0

Constructors

Z |

Fields

- getZ :: ZonedTime

Instances

Read Z Source # |
Methods readsPrec :: Int -> ReadS Z # readList :: ReadS [Z] # readPrec :: ReadPrec Z # readListPrec :: ReadPrec [Z] #
Show Z Source # |
Methods showsPrec :: Int -> Z -> ShowS # show :: Z -> String # showList :: [Z] -> ShowS #
ToJSON Z Source # |
Methods toJSON :: Z -> Value # toEncoding :: Z -> Encoding # toJSONList :: [Z] -> Value # toEncodingList :: [Z] -> Encoding #
FromJSON Z Source # |
Methods parseJSON :: Value -> Parser Z # parseJSONList :: Value -> Parser [Z] #

# Algebra

data ValueF a Source #

An algebra of `Value`

Since: aeson-extra-0.3.1.0

Constructors

ObjectF (ObjectF a) |
ArrayF !(ArrayF a) |
StringF !Text |
NumberF !Scientific |
BoolF !Bool |
NullF |

Instances

Functor ValueF Source # |
Methods fmap :: (a -> b) -> ValueF a -> ValueF b # (<$) :: a -> ValueF b -> ValueF a #
Foldable ValueF Source # |

Methods

fold :: Monoid m => ValueF m -> m #

foldMap :: Monoid m => (a -> m) -> ValueF a -> m #

foldr :: (a -> b -> b) -> b -> ValueF a -> b #

foldr' :: (a -> b -> b) -> b -> ValueF a -> b #

foldl :: (b -> a -> b) -> b -> ValueF a -> b #

foldl' :: (b -> a -> b) -> b -> ValueF a -> b #

foldr1 :: (a -> a -> a) -> ValueF a -> a #

foldl1 :: (a -> a -> a) -> ValueF a -> a #

toList :: ValueF a -> [a] #

null :: ValueF a -> Bool #

length :: ValueF a -> Int #

elem :: Eq a => a -> ValueF a -> Bool #

maximum :: Ord a => ValueF a -> a #

minimum :: Ord a => ValueF a -> a #

sum :: Num a => ValueF a -> a #

product :: Num a => ValueF a -> a #

Traversable ValueF Source # |
Methods traverse :: Applicative f => (a -> f b) -> ValueF a -> f (ValueF b) # sequenceA :: Applicative f => ValueF (f a) -> f (ValueF a) # mapM :: Monad m => (a -> m b) -> ValueF a -> m (ValueF b) # sequence :: Monad m => ValueF (m a) -> m (ValueF a) #
Eq a => Eq (ValueF a) Source # |
Methods (==) :: ValueF a -> ValueF a -> Bool # (/=) :: ValueF a -> ValueF a -> Bool #
Data a => Data (ValueF a) Source # |

Methods

gfoldl :: (forall d b. Data d => c (d -> b) -> d -> c b) -> (forall g. g -> c g) -> ValueF a -> c (ValueF a) #

gunfold :: (forall b r. Data b => c (b -> r) -> c r) -> (forall r. r -> c r) -> Constr -> c (ValueF a) #

toConstr :: ValueF a -> Constr #

dataTypeOf :: ValueF a -> DataType #

dataCast1 :: Typeable (* -> *) t => (forall d. Data d => c (t d)) -> Maybe (c (ValueF a)) #

dataCast2 :: Typeable (* -> * -> *) t => (forall d e. (Data d, Data e) => c (t d e)) -> Maybe (c (ValueF a)) #

gmapT :: (forall b. Data b => b -> b) -> ValueF a -> ValueF a #

gmapQl :: (r -> r' -> r) -> r -> (forall d. Data d => d -> r') -> ValueF a -> r #

gmapQr :: (r' -> r -> r) -> r -> (forall d. Data d => d -> r') -> ValueF a -> r #

gmapQ :: (forall d. Data d => d -> u) -> ValueF a -> [u] #

gmapQi :: Int -> (forall d. Data d => d -> u) -> ValueF a -> u #

gmapM :: Monad m => (forall d. Data d => d -> m d) -> ValueF a -> m (ValueF a) #

gmapMp :: MonadPlus m => (forall d. Data d => d -> m d) -> ValueF a -> m (ValueF a) #

gmapMo :: MonadPlus m => (forall d. Data d => d -> m d) -> ValueF a -> m (ValueF a) #

Read a => Read (ValueF a) Source # |
Methods readsPrec :: Int -> ReadS (ValueF a) # readList :: ReadS [ValueF a] # readPrec :: ReadPrec (ValueF a) # readListPrec :: ReadPrec [ValueF a] #
Show a => Show (ValueF a) Source # |
Methods showsPrec :: Int -> ValueF a -> ShowS # show :: ValueF a -> String # showList :: [ValueF a] -> ShowS #

type ObjectF a = HashMap Text a Source #

A JSON "object" (key/value map).

Since: aeson-extra-0.3.1.0

type ArrayF a = Vector a Source #

A JSON "array" (sequence).

Since: aeson-extra-0.3.1.0

# Merge

merge :: (forall a. (a -> a -> a) -> ValueF a -> ValueF a -> ValueF a) -> Value -> Value -> Value Source #

Generic merge.

For example https://lodash.com/docs#merge:

    lodashMerge :: Value -> Value -> Value
    lodashMerge x y = merge lodashMergeAlg x y

    lodashMergeAlg :: (a -> a -> a) -> ValueF a -> ValueF a -> ValueF a
    lodashMergeAlg r a' b' = case (a', b') of
        (ObjectF a, ObjectF b) -> ObjectF $ alignWith f a b
        (ArrayF a,  ArrayF b)  -> ArrayF $ alignWith f a b
        (_,         b)         -> b
      where f (These x y) = r x y
            f (This x)    = x
            f (That x)    = x

Since: aeson-extra-0.3.1.0

# Stream

streamDecode :: forall a. FromJSON a => ByteString -> ([a], Maybe String) Source #

Lazyly parse `ByteString` with top-level JSON array.

Note: inspecting result's second field will force the list!

    let ~(values, err) = streamDecode bs
    traverse_ processValue values
    maybe (pure ()) printError err

Since: 0.3.2.0

# Template Haskell

mkValue :: String -> Q Exp Source #

Create a `Value` from string representation.

This is useful in tests.

Since: aeson-extra-0.3.1.0

mkValue' :: String -> Q Exp Source #

Like `mkValue`, but replace single quotes with double quotes before.

    > $(mkValue' "{'a': 2 }")
    Object (fromList [("a",Number 2.0)])

Since: aeson-extra-0.3.1.0

# Re-exports

module Data.Aeson.Compat