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
- 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)
- 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
Strict encoding
encodeStrict :: ToJSON a => a -> ByteString Source #
Like encode
, but produces strict ByteString
.
Since: 0.2.3.0
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])
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 # 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 :: forall r r'. (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