A small package containing helpful addititions to aeson.
decodeV functions (analogous to
decode in aeson) that can be used to parse atomic JSON values at the top level. This is not strictly valid JSON, only objects and arrays are allowed at the top level in the specification, but aeson's
encode allows this already. This gives us the nice property
decodeV . encode = Just.
The package also contains the
.=? operator that you can use to optionally construct object pairs:
object ( [ "a" .= foo , "b" .= bar ] ++ catMaybes [ "c" .=? mBaz , "d" .=? mQux ])
Finally it has a
parseNumber function that converts a scientific into
Either Integer Double in case you want to distinguish between integrals and fractionals.
cabal install aeson-utils
aeson 0.9.*. Because of the aeson release
decodeVnow behave the same as
decoderespectively, this package can still be used as a compatibility layer.
The semantics of
decodeVhave been changed to conform to aeson's
decode: They now consume until end of input and strip trailing whitespace.
This is necessary to remove ambiguity when decoding JSON-like values that are not necessarily properly formatted for JSON. For example, parsing a hexadecimal digit sequence that starts with digits but does not have double quotes should fail to parse rather than be interpreted as a number.
parseNumberin favor of