on master help sign in
Add ./ operator for traversing Object heirarchies.
bbc11ebJeremy Fitzhardinge
Data/Aeson.hs+1
@@ -27,6 +27,7 @@ module Data.Aeson
27 , (.=?)
27 , (.=?)
28 , (.:)
28 , (.:)
29 , (.:?)
29 , (.:?)
30+ , (./)
30 , object
31 , object
31 -- * Encoding and parsing
32 -- * Encoding and parsing
32 , encode
33 , encode
Data/Aeson/Types.hs+11
@@ -33,6 +33,7 @@ module Data.Aeson.Types
33 , (.=?)
33 , (.=?)
34 , (.:)
34 , (.:)
35 , (.:?)
35 , (.:?)
36+ , (./)
36 , object
37 , object
37 ) where
38 ) where
38
39
@@ -213,6 +214,16 @@ obj .:? key = case M.lookup key obj of
213 Just v -> parseJSON v
214 Just v -> parseJSON v
214{-# INLINE (.:?) #-}
215{-# INLINE (.:?) #-}
215
216
217+-- | Traverse a object heirarchy.
218+-- This is useful for traversing a JSON object to get to an
219+-- appropriate place before parsing.
220+(./) :: Value -> Text -> Value
221+(Object obj) ./ key = case M.lookup key obj of
222+ Nothing -> Missing
223+ Just v -> v
224+_ ./ _ = Missing
225+{-# INLINE (./) #-}
226+
216-- | Create a 'Value' from a list of name\/value 'Pair's. If duplicate
227-- | Create a 'Value' from a list of name\/value 'Pair's. If duplicate
217-- keys arise, earlier keys and their associated values win.
228-- keys arise, earlier keys and their associated values win.
218object :: [Pair] -> Value
229object :: [Pair] -> Value