Copyright | (C) 2015-2016 Oleg Grenrus |
---|---|
License | BSD3 |
Maintainer | Oleg Grenrus <oleg.grenrus@iki.fi> |
Safe Haskell | None |
Language | Haskell2010 |
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
- class ToJSONMap m k v | m -> k v where
- 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 {}
- newtype Z = Z {}
- data ValueF a
- 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
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)]})
Instances
Functor M Source # | |
Foldable M Source # | |
Defined in Data.Aeson.Extra.Map 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 # elem :: Eq a => a -> M a -> Bool # maximum :: Ord a => M a -> a # | |
Traversable M Source # | |
Eq a => Eq (M a) Source # | |
Ord a => Ord (M a) Source # | |
Read a => Read (M a) Source # | |
Show a => Show (M a) Source # | |
ToJSONMap m k v => ToJSON (M m) Source # | |
Defined in Data.Aeson.Extra.Map | |
FromJSONMap m k v => FromJSON (M m) Source # | |
class FromJSONKey a where Source #
parseJSONKey :: Text -> Parser a Source #
Instances
FromJSONKey Int Source # | |
Defined in Data.Aeson.Extra.Map | |
FromJSONKey Integer Source # | |
Defined in Data.Aeson.Extra.Map | |
FromJSONKey String Source # | |
Defined in Data.Aeson.Extra.Map | |
FromJSONKey Text Source # | |
Defined in Data.Aeson.Extra.Map | |
FromJSONKey Text Source # | |
Defined in Data.Aeson.Extra.Map |
class FromJSONMap m k v | m -> k v where Source #
Instances
(Eq k, Hashable k, FromJSONKey k, FromJSON v) => FromJSONMap (HashMap k v) k v Source # | |
Defined in Data.Aeson.Extra.Map | |
(Ord k, FromJSONKey k, FromJSON v) => FromJSONMap (Map k v) k v Source # | |
Defined in Data.Aeson.Extra.Map |
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
Instances
Bounded (SymTag s) Source # | |
Enum (SymTag s) Source # | |
Eq (SymTag s) Source # | |
Ord (SymTag s) Source # | |
Defined in Data.Aeson.Extra.SymTag | |
Read (SymTag s) Source # | |
Show (SymTag s) Source # | |
KnownSymbol s => ToJSON (SymTag s) Source # | |
Defined in Data.Aeson.Extra.SymTag | |
KnownSymbol s => FromJSON (SymTag s) Source # | |
NFData (SymTag s) Source # | Since: 0.4.1.0 |
Defined in Data.Aeson.Extra.SymTag |
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
Instances
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'.
CollapsedList (f a) |
Instances
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
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
.
Since: aeson-extra-0.2.2.0
A type to parse ZonedTime
Since: aeson-extra-0.2.2.0
Algebra
An algebra of Value
Since: aeson-extra-0.3.1.0
Instances
Functor ValueF Source # | |
Foldable ValueF Source # | |
Defined in Data.Aeson.Extra.Recursive 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 # elem :: Eq a => a -> ValueF a -> Bool # maximum :: Ord a => ValueF a -> a # minimum :: Ord a => ValueF a -> a # | |
Traversable ValueF Source # | |
Eq a => Eq (ValueF a) Source # | |
Data a => Data (ValueF a) Source # | |
Defined in Data.Aeson.Extra.Recursive 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 # | |
Show a => Show (ValueF a) Source # | |
Merge
merge :: (forall a. (a -> a -> a) -> ValueF a -> ValueF a -> ValueF a) -> Value -> Value -> Value Source #
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 #
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