Safe Haskell | None |
---|

This module provides a few small functions to make working with aeson easier. Hopefully at some point they won't be needed anymore.

- module Data.Aeson
- module Data.Aeson.Types
- decodeV :: FromJSON a => ByteString -> Maybe a
- eitherDecodeV :: FromJSON a => ByteString -> Either String a
- fromFloatDigits :: RealFloat a => a -> Scientific
- (.=?) :: ToJSON a => Text -> Maybe a -> Maybe Pair
- parseNumber :: Scientific -> Either Integer Double
- floatingOrInteger :: (RealFloat r, Integral i) => Scientific -> Either r i

# Documentation

module Data.Aeson

module Data.Aeson.Types

# Parsing values

decodeV :: FromJSON a => ByteString -> Maybe aSource

Deserialize any JSON value. Allows atomic values on the top level

eitherDecodeV :: FromJSON a => ByteString -> Either String aSource

Like `decodeV`

, but returns an error message when decoding fails.

# Utilities

fromFloatDigits :: RealFloat a => a -> Scientific

Convert a `RealFloat`

(like a `Double`

or `Float`

) into a `Scientific`

number.

Note that this function uses `floatToDigits`

to compute the digits
and exponent of the `RealFloat`

number. Be aware that the algorithm used in
`floatToDigits`

doesn't work as expected for some numbers, e.g. as
the `Double`

`1e23`

is converted to `9.9999999999999991611392e22`

, and that
value is shown as `9.999999999999999e22`

rather than the shorter `1e23`

; the
algorithm doesn't take the rounding direction for values exactly half-way
between two adjacent representable values into account, so if you have a
value with a short decimal representation exactly half-way between two
adjacent representable values, like `5^23*2^e`

for `e`

close to 23, the
algorithm doesn't know in which direction the short decimal representation
would be rounded and computes more digits

parseNumber :: Scientific -> Either Integer DoubleSource

Deprecated: Use Data.Scientific.floatingOrInteger instead

Convert a Scientific into an Integer if it doesn't have decimal points, otherwise to a Double.

floatingOrInteger :: (RealFloat r, Integral i) => Scientific -> Either r i

`floatingOrInteger`

determines if the scientific is floating point
or integer. In case it's floating-point the scientific is converted
to the desired `RealFloat`

using `toRealFloat`

.