Commits

jsgf committed 7b7c46e

Add ./ operator for traversing Object heirarchies.

./ allows an Object heirarchy to be traversed without parsing anything.
If any of the path components is missing or the wrong type, it returns
Missing.

Comments (0)

Files changed (2)

     , (.=?)
     , (.:)
     , (.:?)
+    , (./)
     , object
     -- * Encoding and parsing
     , encode

Data/Aeson/Types.hs

     , (.=?)
     , (.:)
     , (.:?)
+    , (./)
     , object
     ) where
 
                Just v  -> parseJSON v
 {-# INLINE (.:?) #-}
 
+-- | Traverse a object heirarchy.
+-- This is useful for traversing a JSON object to get to an
+-- appropriate place before parsing.
+(./) :: Value -> Text -> Value
+(Object obj) ./ key = case M.lookup key obj of
+                        Nothing -> Missing
+                        Just v -> v
+_ ./ _              = Missing
+{-# INLINE (./) #-}
+
 -- | Create a 'Value' from a list of name\/value 'Pair's.  If duplicate
 -- keys arise, earlier keys and their associated values win.
 object :: [Pair] -> Value