Copyright | (C) 2015 Oleg Grenrus |
---|---|
License | BSD3 |
Maintainer | Oleg Grenrus <oleg.grenrus@iki.fi> |
Safe Haskell | None |
Language | Haskell2010 |
- 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 = 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, FromJSON (f a), Alternative f) => Object -> Text -> Parser (f a)
- newtype U = U {}
- newtype Z = Z {}
- module Data.Aeson.Compat
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)]})
class FromJSONKey a where Source
parseJSONKey :: Text -> Parser a Source
parseIntegralJSONKey :: Integral a => Text -> Parser a Source
class FromJSONMap m k v | m -> k v where Source
(Eq k, Hashable k, FromJSONKey k, FromJSON v) => FromJSONMap (HashMap k v) k v | |
(Ord k, FromJSONKey k, FromJSON v) => FromJSONMap (Map k v) k v |
Symbol tag
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
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
Functor (SingObject s) | |
Foldable (SingObject s) | |
Traversable (SingObject s) | |
Eq a => Eq (SingObject s a) | |
Ord a => Ord (SingObject s a) | |
Read a => Read (SingObject s a) | |
Show a => Show (SingObject s a) | |
(KnownSymbol s, ToJSON a) => ToJSON (SingObject s a) | |
(KnownSymbol s, FromJSON a) => FromJSON (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'.
CollapsedList (f a) |
Functor f => Functor (CollapsedList f) | |
Foldable f => Foldable (CollapsedList f) | |
Traversable f => Traversable (CollapsedList f) | |
Eq (f a) => Eq (CollapsedList f a) | |
Ord (f a) => Ord (CollapsedList f a) | |
Read (f a) => Read (CollapsedList f a) | |
Show (f a) => Show (CollapsedList f a) | |
(ToJSON a, ToJSON (f a), Foldable f) => ToJSON (CollapsedList f a) | |
(FromJSON a, FromJSON (f a), Alternative f) => FromJSON (CollapsedList f a) |
getCollapsedList :: CollapsedList f a -> f a Source
parseCollapsedList :: (FromJSON a, FromJSON (f a), 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 ZonedTime
Since: aeson-extra-0.2.2.0
Re-exports
module Data.Aeson.Compat