@@ -5,7 +5,7 @@ import Control.Arrow (first)
55import Control.Applicative
66import Data.Aeson
77import Data.Aeson.TH
8−import Data.Aeson.Types (Parser)
8+import Data.Aeson.Types (Parser, Pair)
99import Data.Char
1010import Data.Hashable (Hashable)
1111import Data.HashMap.Strict (HashMap)
@@ -69,3 +69,8 @@ genericParseJSONWithSub _ _ _ = error "impossible"
6969(<+>) :: Value -> Value -> Value
7070Object x <+> Object y = Object (x <> y)
7171_ <+> _ = error "impossible"
72+
73+withDefaults :: (Value -> Parser a) -> [Pair] -> Value -> Parser a
74+withDefaults parser defs json@(Object _) = parser (json <+> object defs)
75+withDefaults _ _ _ = empty
76+