aeson-extra-0.4.1.1: 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
  - parseJSONKey :: Text -> Parser a
- parseIntegralJSONKey :: Integral a => Text -> Parser a
- class FromJSONMap m k v | m -> k v where
  - parseJSONMap :: HashMap Text Value -> Parser m
- class ToJSONKey a where
  - toJSONKey :: a -> Text
- class ToJSONMap m k v | m -> k v where
  - toJSONMap :: m -> HashMap Text Value
- data SymTag (s :: Symbol) = SymTag
- newtype SingObject (s :: Symbol) 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
- lodashMerge :: 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 # |
Instance details Defined in Data.Aeson.Extra.Map Methods fmap :: (a -> b) -> M a -> M b Source # (<$) :: a -> M b -> M a Source #
Foldable M Source # |

Instance details

Defined in Data.Aeson.Extra.Map

Methods

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

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

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

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

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

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

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

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

toList :: M a -> [a] Source #

null :: M a -> Bool Source #

length :: M a -> Int Source #

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

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

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

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

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

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

class FromJSONKey a where Source #

Methods

parseJSONKey :: Text -> Parser a Source #

Instances

FromJSONKey Int Source # |
Instance details Defined in Data.Aeson.Extra.Map Methods parseJSONKey :: Text -> Parser Int Source #
FromJSONKey Integer Source # |
Instance details Defined in Data.Aeson.Extra.Map Methods parseJSONKey :: Text -> Parser Integer Source #
FromJSONKey Text Source # |
Instance details Defined in Data.Aeson.Extra.Map Methods parseJSONKey :: Text -> Parser Text Source #
FromJSONKey Text Source # |
Instance details Defined in Data.Aeson.Extra.Map Methods parseJSONKey :: Text0 -> Parser Text Source #
FromJSONKey String Source # |
Instance details Defined in Data.Aeson.Extra.Map Methods parseJSONKey :: Text -> Parser String Source #

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

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

Methods

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

Instances

(Eq k, Hashable k, FromJSONKey k, FromJSON v) => FromJSONMap (HashMap k v) k v Source # |
Instance details Defined in Data.Aeson.Extra.Map Methods parseJSONMap :: HashMap Text Value -> Parser (HashMap k v) Source #
(Ord k, FromJSONKey k, FromJSON v) => FromJSONMap (Map k v) k v Source # |
Instance details Defined in Data.Aeson.Extra.Map Methods parseJSONMap :: HashMap Text Value -> Parser (Map k v) Source #

class ToJSONKey a where Source #

Methods

toJSONKey :: a -> Text Source #

Instances

ToJSONKey Int Source # |
Instance details Defined in Data.Aeson.Extra.Map Methods toJSONKey :: Int -> Text Source #
ToJSONKey Integer Source # |
Instance details Defined in Data.Aeson.Extra.Map Methods toJSONKey :: Integer -> Text Source #
ToJSONKey Text Source # |
Instance details Defined in Data.Aeson.Extra.Map Methods toJSONKey :: Text -> Text Source #
ToJSONKey Text Source # |
Instance details Defined in Data.Aeson.Extra.Map Methods toJSONKey :: Text -> Text0 Source #
ToJSONKey String Source # |
Instance details Defined in Data.Aeson.Extra.Map Methods toJSONKey :: String -> Text Source #

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

Methods

toJSONMap :: m -> HashMap Text Value Source #

Instances

(ToJSONKey k, ToJSON v) => ToJSONMap (HashMap k v) k v Source # |
Instance details Defined in Data.Aeson.Extra.Map Methods toJSONMap :: HashMap k v -> HashMap Text Value Source #
(ToJSONKey k, ToJSON v) => ToJSONMap (Map k v) k v Source # |
Instance details Defined in Data.Aeson.Extra.Map Methods toJSONMap :: Map k v -> HashMap Text Value Source #

# Symbol tag

data SymTag (s :: Symbol) 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 # |
Instance details Defined in Data.Aeson.Extra.SymTag Methods minBound :: SymTag s Source # maxBound :: SymTag s Source #
Enum (SymTag s) Source # |

Instance details

Defined in Data.Aeson.Extra.SymTag

Methods

succ :: SymTag s -> SymTag s Source #

pred :: SymTag s -> SymTag s Source #

toEnum :: Int -> SymTag s Source #

fromEnum :: SymTag s -> Int Source #

enumFrom :: SymTag s -> [SymTag s] Source #

enumFromThen :: SymTag s -> SymTag s -> [SymTag s] Source #

enumFromTo :: SymTag s -> SymTag s -> [SymTag s] Source #

enumFromThenTo :: SymTag s -> SymTag s -> SymTag s -> [SymTag s] Source #

Eq (SymTag s) Source # |
Instance details Defined in Data.Aeson.Extra.SymTag Methods (==) :: SymTag s -> SymTag s -> Bool Source # (/=) :: SymTag s -> SymTag s -> Bool Source #
Ord (SymTag s) Source # |
Instance details Defined in Data.Aeson.Extra.SymTag Methods compare :: SymTag s -> SymTag s -> Ordering Source # (<) :: SymTag s -> SymTag s -> Bool Source # (<=) :: SymTag s -> SymTag s -> Bool Source # (>) :: SymTag s -> SymTag s -> Bool Source # (>=) :: SymTag s -> SymTag s -> Bool Source # max :: SymTag s -> SymTag s -> SymTag s Source # min :: SymTag s -> SymTag s -> SymTag s Source #
Read (SymTag s) Source # |
Instance details Defined in Data.Aeson.Extra.SymTag Methods readsPrec :: Int -> ReadS (SymTag s) Source # readList :: ReadS [SymTag s] Source # readPrec :: ReadPrec (SymTag s) Source # readListPrec :: ReadPrec [SymTag s] Source #
Show (SymTag s) Source # |
Instance details Defined in Data.Aeson.Extra.SymTag Methods showsPrec :: Int -> SymTag s -> ShowS Source # show :: SymTag s -> String Source # showList :: [SymTag s] -> ShowS Source #
KnownSymbol s => ToJSON (SymTag s) Source # |
Instance details Defined in Data.Aeson.Extra.SymTag Methods toJSON :: SymTag s -> Value Source # toEncoding :: SymTag s -> Encoding Source # toJSONList :: [SymTag s] -> Value Source # toEncodingList :: [SymTag s] -> Encoding Source #
KnownSymbol s => FromJSON (SymTag s) Source # |
Instance details Defined in Data.Aeson.Extra.SymTag Methods parseJSON :: Value -> Parser (SymTag s) Source # parseJSONList :: Value -> Parser [SymTag s] Source #
NFData (SymTag s) Source # | Since: 0.4.1.0
Instance details Defined in Data.Aeson.Extra.SymTag Methods rnf :: SymTag s -> () Source #

# Singleton object

newtype SingObject (s :: Symbol) 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 # |
Instance details Defined in Data.Aeson.Extra.SingObject Methods fmap :: (a -> b) -> SingObject s a -> SingObject s b Source # (<$) :: a -> SingObject s b -> SingObject s a Source #
Foldable (SingObject s) Source # |

Instance details

Defined in Data.Aeson.Extra.SingObject

Methods

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

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

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

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

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

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

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

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

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

null :: SingObject s a -> Bool Source #

length :: SingObject s a -> Int Source #

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

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

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

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

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

Traversable (SingObject s) Source # |
Instance details Defined in Data.Aeson.Extra.SingObject Methods traverse :: Applicative f => (a -> f b) -> SingObject s a -> f (SingObject s b) Source # sequenceA :: Applicative f => SingObject s (f a) -> f (SingObject s a) Source # mapM :: Monad m => (a -> m b) -> SingObject s a -> m (SingObject s b) Source # sequence :: Monad m => SingObject s (m a) -> m (SingObject s a) Source #
KnownSymbol s => ToJSON1 (SingObject s) Source # |

Instance details

Defined in Data.Aeson.Extra.SingObject

Methods

liftToJSON :: (a -> Value) -> ([a] -> Value) -> SingObject s a -> Value Source #

liftToJSONList :: (a -> Value) -> ([a] -> Value) -> [SingObject s a] -> Value Source #

liftToEncoding :: (a -> Encoding) -> ([a] -> Encoding) -> SingObject s a -> Encoding Source #

liftToEncodingList :: (a -> Encoding) -> ([a] -> Encoding) -> [SingObject s a] -> Encoding Source #

KnownSymbol s => FromJSON1 (SingObject s) Source # |
Instance details Defined in Data.Aeson.Extra.SingObject Methods liftParseJSON :: (Value -> Parser a) -> (Value -> Parser [a]) -> Value -> Parser (SingObject s a) Source # liftParseJSONList :: (Value -> Parser a) -> (Value -> Parser [a]) -> Value -> Parser [SingObject s a] Source #
Eq a => Eq (SingObject s a) Source # |
Instance details Defined in Data.Aeson.Extra.SingObject Methods (==) :: SingObject s a -> SingObject s a -> Bool Source # (/=) :: SingObject s a -> SingObject s a -> Bool Source #
Ord a => Ord (SingObject s a) Source # |

Instance details

Defined in Data.Aeson.Extra.SingObject

Methods

compare :: SingObject s a -> SingObject s a -> Ordering Source #

(<) :: SingObject s a -> SingObject s a -> Bool Source #

(<=) :: SingObject s a -> SingObject s a -> Bool Source #

(>) :: SingObject s a -> SingObject s a -> Bool Source #

(>=) :: SingObject s a -> SingObject s a -> Bool Source #

max :: SingObject s a -> SingObject s a -> SingObject s a Source #

min :: SingObject s a -> SingObject s a -> SingObject s a Source #

Read a => Read (SingObject s a) Source # |
Instance details Defined in Data.Aeson.Extra.SingObject Methods readsPrec :: Int -> ReadS (SingObject s a) Source # readList :: ReadS [SingObject s a] Source # readPrec :: ReadPrec (SingObject s a) Source # readListPrec :: ReadPrec [SingObject s a] Source #
Show a => Show (SingObject s a) Source # |
Instance details Defined in Data.Aeson.Extra.SingObject Methods showsPrec :: Int -> SingObject s a -> ShowS Source # show :: SingObject s a -> String Source # showList :: [SingObject s a] -> ShowS Source #
(KnownSymbol s, ToJSON a) => ToJSON (SingObject s a) Source # |
Instance details Defined in Data.Aeson.Extra.SingObject Methods toJSON :: SingObject s a -> Value Source # toEncoding :: SingObject s a -> Encoding Source # toJSONList :: [SingObject s a] -> Value Source # toEncodingList :: [SingObject s a] -> Encoding Source #
(KnownSymbol s, FromJSON a) => FromJSON (SingObject s a) Source # |
Instance details Defined in Data.Aeson.Extra.SingObject Methods parseJSON :: Value -> Parser (SingObject s a) Source # parseJSONList :: Value -> Parser [SingObject s a] Source #
NFData a => NFData (SingObject s a) Source # | Since: 0.4.1.0
Instance details Defined in Data.Aeson.Extra.SingObject Methods rnf :: SingObject s a -> () Source #

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 # |
Instance details Defined in Data.Aeson.Extra.CollapsedList Methods fmap :: (a -> b) -> CollapsedList f a -> CollapsedList f b Source # (<$) :: a -> CollapsedList f b -> CollapsedList f a Source #
Foldable f => Foldable (CollapsedList f) Source # |

Instance details

Defined in Data.Aeson.Extra.CollapsedList

Methods

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

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

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

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

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

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

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

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

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

null :: CollapsedList f a -> Bool Source #

length :: CollapsedList f a -> Int Source #

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

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

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

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

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

Traversable f => Traversable (CollapsedList f) Source # |

Instance details

Defined in Data.Aeson.Extra.CollapsedList

Methods

traverse :: Applicative f0 => (a -> f0 b) -> CollapsedList f a -> f0 (CollapsedList f b) Source #

sequenceA :: Applicative f0 => CollapsedList f (f0 a) -> f0 (CollapsedList f a) Source #

mapM :: Monad m => (a -> m b) -> CollapsedList f a -> m (CollapsedList f b) Source #

sequence :: Monad m => CollapsedList f (m a) -> m (CollapsedList f a) Source #

(ToJSON1 f, Foldable f) => ToJSON1 (CollapsedList f) Source # |

Instance details

Defined in Data.Aeson.Extra.CollapsedList

Methods

liftToJSON :: (a -> Value) -> ([a] -> Value) -> CollapsedList f a -> Value Source #

liftToJSONList :: (a -> Value) -> ([a] -> Value) -> [CollapsedList f a] -> Value Source #

liftToEncoding :: (a -> Encoding) -> ([a] -> Encoding) -> CollapsedList f a -> Encoding Source #

liftToEncodingList :: (a -> Encoding) -> ([a] -> Encoding) -> [CollapsedList f a] -> Encoding Source #

(FromJSON1 f, Alternative f) => FromJSON1 (CollapsedList f) Source # |
Instance details Defined in Data.Aeson.Extra.CollapsedList Methods liftParseJSON :: (Value -> Parser a) -> (Value -> Parser [a]) -> Value -> Parser (CollapsedList f a) Source # liftParseJSONList :: (Value -> Parser a) -> (Value -> Parser [a]) -> Value -> Parser [CollapsedList f a] Source #
Eq (f a) => Eq (CollapsedList f a) Source # |
Instance details Defined in Data.Aeson.Extra.CollapsedList Methods (==) :: CollapsedList f a -> CollapsedList f a -> Bool Source # (/=) :: CollapsedList f a -> CollapsedList f a -> Bool Source #
Ord (f a) => Ord (CollapsedList f a) Source # |

Instance details

Defined in Data.Aeson.Extra.CollapsedList

Methods

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

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

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

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

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

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

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

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

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 # |
Instance details Defined in Data.Aeson.Extra.Time Methods (==) :: U -> U -> Bool Source # (/=) :: U -> U -> Bool Source #
Ord U Source # |
Instance details Defined in Data.Aeson.Extra.Time Methods compare :: U -> U -> Ordering Source # (<) :: U -> U -> Bool Source # (<=) :: U -> U -> Bool Source # (>) :: U -> U -> Bool Source # (>=) :: U -> U -> Bool Source # max :: U -> U -> U Source # min :: U -> U -> U Source #
Read U Source # |
Instance details Defined in Data.Aeson.Extra.Time Methods readsPrec :: Int -> ReadS U Source # readList :: ReadS [U] Source # readPrec :: ReadPrec U Source # readListPrec :: ReadPrec [U] Source #
Show U Source # |
Instance details Defined in Data.Aeson.Extra.Time Methods showsPrec :: Int -> U -> ShowS Source # show :: U -> String Source # showList :: [U] -> ShowS Source #
ToJSON U Source # |
Instance details Defined in Data.Aeson.Extra.Time Methods toJSON :: U -> Value Source # toEncoding :: U -> Encoding Source # toJSONList :: [U] -> Value Source # toEncodingList :: [U] -> Encoding Source #
FromJSON U Source # |
Instance details Defined in Data.Aeson.Extra.Time Methods parseJSON :: Value -> Parser U Source # parseJSONList :: Value -> Parser [U] Source #

newtype Z Source #

A type to parse `ZonedTime`

Since: aeson-extra-0.2.2.0

Constructors

Z |

Fields

- getZ :: ZonedTime

Instances

Read Z Source # |
Instance details Defined in Data.Aeson.Extra.Time Methods readsPrec :: Int -> ReadS Z Source # readList :: ReadS [Z] Source # readPrec :: ReadPrec Z Source # readListPrec :: ReadPrec [Z] Source #
Show Z Source # |
Instance details Defined in Data.Aeson.Extra.Time Methods showsPrec :: Int -> Z -> ShowS Source # show :: Z -> String Source # showList :: [Z] -> ShowS Source #
ToJSON Z Source # |
Instance details Defined in Data.Aeson.Extra.Time Methods toJSON :: Z -> Value Source # toEncoding :: Z -> Encoding Source # toJSONList :: [Z] -> Value Source # toEncodingList :: [Z] -> Encoding Source #
FromJSON Z Source # |
Instance details Defined in Data.Aeson.Extra.Time Methods parseJSON :: Value -> Parser Z Source # parseJSONList :: Value -> Parser [Z] Source #

# 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 # |
Instance details Defined in Data.Aeson.Extra.Recursive Methods fmap :: (a -> b) -> ValueF a -> ValueF b Source # (<$) :: a -> ValueF b -> ValueF a Source #
Foldable ValueF Source # |

Instance details

Defined in Data.Aeson.Extra.Recursive

Methods

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

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

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

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

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

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

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

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

toList :: ValueF a -> [a] Source #

null :: ValueF a -> Bool Source #

length :: ValueF a -> Int Source #

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

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

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

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

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

Traversable ValueF Source # |
Instance details Defined in Data.Aeson.Extra.Recursive Methods traverse :: Applicative f => (a -> f b) -> ValueF a -> f (ValueF b) Source # sequenceA :: Applicative f => ValueF (f a) -> f (ValueF a) Source # mapM :: Monad m => (a -> m b) -> ValueF a -> m (ValueF b) Source # sequence :: Monad m => ValueF (m a) -> m (ValueF a) Source #
Eq a => Eq (ValueF a) Source # |
Instance details Defined in Data.Aeson.Extra.Recursive Methods (==) :: ValueF a -> ValueF a -> Bool Source # (/=) :: ValueF a -> ValueF a -> Bool Source #
Data a => Data (ValueF a) Source # |

Instance details

Defined in Data.Aeson.Extra.Recursive

Methods

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

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

toConstr :: ValueF a -> Constr Source #

dataTypeOf :: ValueF a -> DataType Source #

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

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

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

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

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

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

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

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

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

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

Read a => Read (ValueF a) Source # |
Instance details Defined in Data.Aeson.Extra.Recursive Methods readsPrec :: Int -> ReadS (ValueF a) Source # readList :: ReadS [ValueF a] Source # readPrec :: ReadPrec (ValueF a) Source # readListPrec :: ReadPrec [ValueF a] Source #
Show a => Show (ValueF a) Source # |
Instance details Defined in Data.Aeson.Extra.Recursive Methods showsPrec :: Int -> ValueF a -> ShowS Source # show :: ValueF a -> String Source # showList :: [ValueF a] -> ShowS Source #

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 see `lodashMerge`.

Since: aeson-extra-0.3.1.0

lodashMerge :: Value -> Value -> Value Source #

Example of using `merge`. see https://lodash.com/docs#merge:

Note: not tested against JavaScript lodash, so may disagree in the results.

Since: 0.4.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