Data.Aeson.Compat

aeson-compat-0.3.1.0: Compatibility layer for aeson

Copyright | (C) 2015 Oleg Grenrus
License | BSD3
Maintainer | Oleg Grenrus <oleg.grenrus@iki.fi>
Safe Haskell | None
Language | Haskell2010

Data.Aeson.Compat

Contents

- Generic decoding functions
- Either decoding functions
- Operators
- Re-exports

Description

Compatibility notices

- `decode` etc. work as in `aeson >=0.9`
- but it is generalised to work in any `MonadThrow` (that is extra)
- `.:?` works as in `aeson <0.10`
- `.:!` works as `.:?` in `aeson ==0.10`
- Orphan instances `FromJSON` `Day` and `FromJSON` `LocalTime` for `aeson <0.10`

Synopsis

- decode :: (FromJSON a, MonadThrow m) => ByteString -> m a
- decode' :: (FromJSON a, MonadThrow m) => ByteString -> m a
- decodeStrict :: (FromJSON a, MonadThrow m) => ByteString -> m a
- decodeStrict' :: (FromJSON a, MonadThrow m) => ByteString -> m a
- newtype AesonException = AesonException String
- eitherDecode :: FromJSON a => ByteString -> Either String a
- eitherDecode' :: FromJSON a => ByteString -> Either String a
- eitherDecodeStrict :: FromJSON a => ByteString -> Either String a
- eitherDecodeStrict' :: FromJSON a => ByteString -> Either String a
- (.:?) :: FromJSON a => Object -> Text -> Parser (Maybe a)
- (.:!) :: FromJSON a => Object -> Text -> Parser (Maybe a)
- module Data.Aeson

# Generic decoding functions

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

Like original `decode` but in arbitrary `MonadThrow`.

Parse a top-level JSON value, i.e. also strings, numbers etc.

decode' :: (FromJSON a, MonadThrow m) => ByteString -> m a

Like original `decode'` but in arbitrary `MonadThrow`.

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

Like original `decodeStrict` but in arbitrary `MonadThrow`.

decodeStrict' :: (FromJSON a, MonadThrow m) => ByteString -> m a

Like original `decodeStrict'` but in arbitrary `MonadThrow`.

newtype AesonException

Exception thrown by `decode` - family of functions in this module.

Constructors

AesonException String |

Instances

Show AesonException |
Exception AesonException |

# Either decoding functions

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

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

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

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

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

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

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

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

# Operators

(.:?) :: FromJSON a => Object -> Text -> Parser (Maybe a)

Retrieve the value associated with the given key of an `Object`. The result is `Nothing` if the key is not present, or `empty` if the value cannot be converted to the desired type.

This accessor is most useful if the key and value can be absent from an object without affecting its validity. If the key and value are mandatory, use `.:` instead.

This operator is consistent in `aeson >=0.7 && <0.11`

(.:!) :: FromJSON a => Object -> Text -> Parser (Maybe a)

Like `.:?`, but the resulting parser will fail, if the key is present but is `Null`.

# Re-exports

Original `.:?` operator is not re-exported

module Data.Aeson