-- Hoogle documentation, generated by Haddock
-- See Hoogle, http://www.haskell.org/hoogle/


-- | Utilities for working with Aeson.
--   
--   Utilities for working with Aeson.
@package aeson-utils
@version 0.3.0.2


-- | 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.Utils

-- | Deserialize any JSON value. Allows atomic values on the top level
decodeV :: FromJSON a => ByteString -> Maybe a

-- | Like <a>decodeV</a>, but returns an error message when decoding fails.
eitherDecodeV :: FromJSON a => ByteString -> Either String a

-- | Convert a <a>RealFloat</a> (like a <a>Double</a> or <a>Float</a>) into
--   a <a>Scientific</a> number.
--   
--   Note that this function uses <a>floatToDigits</a> to compute the
--   digits and exponent of the <a>RealFloat</a> number. Be aware that the
--   algorithm used in <a>floatToDigits</a> doesn't work as expected for
--   some numbers, e.g. as the <a>Double</a> <tt>1e23</tt> is converted to
--   <tt>9.9999999999999991611392e22</tt>, and that value is shown as
--   <tt>9.999999999999999e22</tt> rather than the shorter <tt>1e23</tt>;
--   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 <tt>5^23*2^e</tt> for
--   <tt>e</tt> close to 23, the algorithm doesn't know in which direction
--   the short decimal representation would be rounded and computes more
--   digits
fromFloatDigits :: RealFloat a => a -> Scientific

-- | Optionally create a Pair.
(.=?) :: ToJSON a => Text -> Maybe a -> Maybe Pair

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

-- | <i>Deprecated: Use Data.Scientific.floatingOrInteger instead</i>
parseNumber :: Scientific -> Either Integer Double

-- | <tt>floatingOrInteger</tt> determines if the scientific is floating
--   point or integer.
--   
--   In case it's floating-point the scientific is converted to the desired
--   <a>RealFloat</a> using <a>toRealFloat</a> and wrapped in <a>Left</a>.
--   
--   In case it's integer to scientific is converted to the desired
--   <a>Integral</a> and wrapped in <a>Right</a>.
--   
--   <i>WARNING:</i> To convert the scientific to an integral the magnitude
--   <tt>10^e</tt> needs to be computed. If applied to a huge exponent this
--   could take a long time. Even worse, when the destination type is
--   unbounded (i.e. <a>Integer</a>) it could fill up all space and crash
--   your program! So don't apply this function to untrusted input but use
--   <a>toBoundedInteger</a> instead.
--   
--   Also see: <a>isFloating</a> or <a>isInteger</a>.
floatingOrInteger :: (RealFloat r, Integral i) => Scientific -> Either r i
