Data.Aeson.Decoding

aeson-2.2.1.0: Fast JSON parsing and encoding

Safe Haskell | None
Language | Haskell2010

Data.Aeson.Decoding

Description

Convertion to and from `aeson` `Value`.

Synopsis

- decode :: FromJSON a => ByteString -> Maybe a
- eitherDecode :: FromJSON a => ByteString -> Either String a
- throwDecode :: (FromJSON a, MonadThrow m) => ByteString -> m a
- decodeStrict :: FromJSON a => ByteString -> Maybe a
- eitherDecodeStrict :: FromJSON a => ByteString -> Either String a
- throwDecodeStrict :: (FromJSON a, MonadThrow m) => ByteString -> m a
- decodeStrictText :: FromJSON a => Text -> Maybe a
- eitherDecodeStrictText :: FromJSON a => Text -> Either String a
- throwDecodeStrictText :: (FromJSON a, MonadThrow m) => Text -> m a
- toEitherValue :: Tokens k e -> Either e (Value, k)
- unescapeText :: ByteString -> Either UnicodeException Text

# Documentation

decode :: FromJSON a => ByteString -> Maybe a #

Efficiently deserialize a JSON value from a lazy `ByteString`. If this fails due to incomplete or invalid input, `Nothing` is returned.

eitherDecode :: FromJSON a => ByteString -> Either String a #

Like `decode` but returns an error message when decoding fails.

throwDecode :: (FromJSON a, MonadThrow m) => ByteString -> m a #

Like `decode` but throws an `AesonException` when decoding fails.

`throwDecode` is in `aeson` since 2.1.2.0, but this variant is added later.

decodeStrict :: FromJSON a => ByteString -> Maybe a #

Efficiently deserialize a JSON value from a strict `ByteString`. If this fails due to incomplete or invalid input, `Nothing` is returned.

eitherDecodeStrict :: FromJSON a => ByteString -> Either String a #

Like `decodeStrict` but returns an error message when decoding fails.

throwDecodeStrict :: (FromJSON a, MonadThrow m) => ByteString -> m a #

Like `decodeStrict` but throws an `AesonException` when decoding fails.

decodeStrictText :: FromJSON a => Text -> Maybe a #

Efficiently deserialize a JSON value from a strict `ByteString`. If this fails due to incomplete or invalid input, `Nothing` is returned.

Since: 2.2.1.0

eitherDecodeStrictText :: FromJSON a => Text -> Either String a #

Like `decodeStrictText` but returns an error message when decoding fails.

Since: 2.2.1.0

throwDecodeStrictText :: (FromJSON a, MonadThrow m) => Text -> m a #

Like `decodeStrictText` but throws an `AesonException` when decoding fails.

Since: 2.2.1.0

toEitherValue #

Arguments

:: Tokens k e | tokens
-> Either e (Value, k) | either token error or value and leftover.

Convert `Tokens` to `Value`.

The resulting value will be in normal form if its forced. In other words, there shouldn't be thunks inside.

unescapeText :: ByteString -> Either UnicodeException Text #

Unescape JSON text literal.

This function is exporeted mostly for testing and benchmarking purposes.