aeson-compat-0.3.9: 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

- Encoding and decoding
  - Direct encoding
  - Variants for strict bytestrings
- Core JSON types
- Convenience types
- Type conversion
  - Generic JSON classes and options
- Inspecting ``Value`s`
- Constructors and accessors
- Parsing

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.11`
- `.:!` works as in `aeson ||=0.11` and as `.:?` did in `aeson ==0.10.*`
- Orphan instances `FromJSON` `Day` and `FromJSON` `LocalTime` for `aeson <0.10`
- `Encoding` related functionality is not added. It's present only with `aeson >=0.10`

Synopsis

- decode :: (FromJSON a, MonadThrow m) => ByteString -> m a
- decode' :: (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
- encode :: ToJSON a => a -> ByteString
- decodeStrict :: (FromJSON a, MonadThrow m) => ByteString -> m a
- decodeStrict' :: (FromJSON a, MonadThrow m) => ByteString -> m a
- eitherDecodeStrict :: FromJSON a => ByteString -> Either String a
- eitherDecodeStrict' :: FromJSON a => ByteString -> Either String a
- data Value
  - = Object !Object
  - | Array !Array
  - | String !Text
  - | Number !Scientific
  - | Bool !Bool
  - | Null
- type Encoding = Encoding' Value
- fromEncoding :: Encoding' tag -> Builder
- type Array = Vector Value
- type Object = HashMap Text Value
- newtype DotNetTime = DotNetTime {
  - fromDotNetTime :: UTCTime
  }
- class FromJSON a where
  - parseJSON :: Value -> Parser a
  - parseJSONList :: Value -> Parser [a]
- data Result a
  - = Error String
  - | Success a
- fromJSON :: FromJSON a => Value -> Result a
- class ToJSON a where
  - toJSON :: a -> Value
  - toEncoding :: a -> Encoding
  - toJSONList :: [a] -> Value
  - toEncodingList :: [a] -> Encoding
- class KeyValue kv where
  - (.=) :: ToJSON v => Text -> v -> kv
- class GFromJSON arity (f :: Type -> Type)
- type GToJSON = GToJSON Value
- type GToEncoding = GToJSON Encoding
- genericToJSON :: (Generic a, GToJSON Value Zero (Rep a)) => Options -> a -> Value
- genericToEncoding :: (Generic a, GToJSON Encoding Zero (Rep a)) => Options -> a -> Encoding
- genericParseJSON :: (Generic a, GFromJSON Zero (Rep a)) => Options -> Value -> Parser a
- defaultOptions :: Options
- withObject :: String -> (Object -> Parser a) -> Value -> Parser a
- withText :: String -> (Text -> Parser a) -> Value -> Parser a
- withArray :: String -> (Array -> Parser a) -> Value -> Parser a
- withNumber :: String -> (Number -> Parser a) -> Value -> Parser a
- withScientific :: String -> (Scientific -> Parser a) -> Value -> Parser a
- withBool :: String -> (Bool -> Parser a) -> Value -> Parser a
- withEmbeddedJSON :: String -> (Value -> Parser a) -> Value -> Parser a
- data Series
- pairs :: Series -> Encoding
- foldable :: (Foldable t, ToJSON a) => t a -> Encoding
- (.:) :: FromJSON a => Object -> Text -> Parser a
- (.:?) :: FromJSON a => Object -> Text -> Parser (Maybe a)
- (.:!) :: FromJSON a => Object -> Text -> Parser (Maybe a)
- (.!=) :: Parser (Maybe a) -> a -> Parser a
- object :: [Pair] -> Value
- json :: Parser Value
- json' :: Parser Value
- value :: Parser Value
- value' :: Parser Value
- data Parser a

# Encoding and decoding

## Direct encoding

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

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 Source #

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

newtype AesonException Source #

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

Constructors

AesonException String |

#### Instances

Instances details

Show AesonException Source # |
Instance details Defined in Data.Aeson.Compat Methods showsPrec :: Int -> AesonException -> ShowS show :: AesonException -> String showList :: [AesonException] -> ShowS
Exception AesonException Source # |
Instance details Defined in Data.Aeson.Compat Methods toException :: AesonException -> SomeException # fromException :: SomeException -> Maybe AesonException # displayException :: AesonException -> String #

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

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

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

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

encode :: ToJSON a => a -> ByteString Source #

Efficiently serialize a JSON value as a lazy `ByteString`.

This is implemented in terms of the `ToJSON` class's `toEncoding` method.

## Variants for strict bytestrings

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

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

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

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

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

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

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

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

# Core JSON types

data Value Source #

A JSON value represented as a Haskell value.

Constructors

Object !Object |
Array !Array |
String !Text |
Number !Scientific |
Bool !Bool |
Null |

#### Instances

Instances details

Eq Value |
Instance details Defined in Data.Aeson.Types.Internal Methods (==) :: Value -> Value -> Bool (/=) :: Value -> Value -> Bool
Data Value |

Instance details

Defined in Data.Aeson.Types.Internal

Methods

gfoldl :: (forall d b. Data d => c (d -> b) -> d -> c b) -> (forall g. g -> c g) -> Value -> c Value

gunfold :: (forall b r. Data b => c (b -> r) -> c r) -> (forall r. r -> c r) -> Constr -> c Value

toConstr :: Value -> Constr

dataTypeOf :: Value -> DataType

dataCast1 :: Typeable t => (forall d. Data d => c (t d)) -> Maybe (c Value)

dataCast2 :: Typeable t => (forall d e. (Data d, Data e) => c (t d e)) -> Maybe (c Value)

gmapT :: (forall b. Data b => b -> b) -> Value -> Value

gmapQl :: (r -> r' -> r) -> r -> (forall d. Data d => d -> r') -> Value -> r

gmapQr :: forall r r'. (r' -> r -> r) -> r -> (forall d. Data d => d -> r') -> Value -> r

gmapQ :: (forall d. Data d => d -> u) -> Value -> [u]

gmapQi :: Int -> (forall d. Data d => d -> u) -> Value -> u

gmapM :: Monad m => (forall d. Data d => d -> m d) -> Value -> m Value

gmapMp :: MonadPlus m => (forall d. Data d => d -> m d) -> Value -> m Value

gmapMo :: MonadPlus m => (forall d. Data d => d -> m d) -> Value -> m Value

Read Value |
Instance details Defined in Data.Aeson.Types.Internal Methods readsPrec :: Int -> ReadS Value # readList :: ReadS [Value] # readPrec :: ReadPrec Value # readListPrec :: ReadPrec [Value] #
Show Value |
Instance details Defined in Data.Aeson.Types.Internal Methods showsPrec :: Int -> Value -> ShowS show :: Value -> String showList :: [Value] -> ShowS
IsString Value |
Instance details Defined in Data.Aeson.Types.Internal Methods fromString :: String -> Value
Generic Value |
Instance details Defined in Data.Aeson.Types.Internal Associated Types type Rep Value :: Type -> Type Methods from :: Value -> Rep Value x to :: Rep Value x -> Value
Lift Value |
Instance details Defined in Data.Aeson.Types.Internal Methods lift :: Value -> Q Exp
Hashable Value |
Instance details Defined in Data.Aeson.Types.Internal Methods hashWithSalt :: Int -> Value -> Int Source # hash :: Value -> Int Source #
ToJSON Value |
Instance details Defined in Data.Aeson.Types.ToJSON Methods toJSON :: Value -> Value Source # toEncoding :: Value -> Encoding Source # toJSONList :: [Value] -> Value Source # toEncodingList :: [Value] -> Encoding Source #
KeyValue Object | Constructs a singleton `HashMap`. For calling functions that demand an `Object` for constructing objects. To be used in conjunction with `mconcat`. Prefer to use `object` where possible.
Instance details Defined in Data.Aeson.Types.ToJSON Methods (.=) :: ToJSON v => Text -> v -> Object Source #
KeyValue Pair |
Instance details Defined in Data.Aeson.Types.ToJSON Methods (.=) :: ToJSON v => Text -> v -> Pair Source #
FromJSON Value |
Instance details Defined in Data.Aeson.Types.FromJSON Methods parseJSON :: Value -> Parser Value Source # parseJSONList :: Value -> Parser [Value] Source #
NFData Value |
Instance details Defined in Data.Aeson.Types.Internal Methods rnf :: Value -> ()
FromString Encoding |
Instance details Defined in Data.Aeson.Types.ToJSON Methods fromString :: String -> Encoding
FromString Value |
Instance details Defined in Data.Aeson.Types.ToJSON Methods fromString :: String -> Value
GToJSON Encoding arity (U1 :: Type -> Type) |
Instance details Defined in Data.Aeson.Types.ToJSON Methods gToJSON :: Options -> ToArgs Encoding arity a -> U1 a -> Encoding
GToJSON Value arity (V1 :: Type -> Type) |
Instance details Defined in Data.Aeson.Types.ToJSON Methods gToJSON :: Options -> ToArgs Value arity a -> V1 a -> Value
GToJSON Value arity (U1 :: Type -> Type) |
Instance details Defined in Data.Aeson.Types.ToJSON Methods gToJSON :: Options -> ToArgs Value arity a -> U1 a -> Value
ToJSON1 f => GToJSON Encoding One (Rec1 f) |
Instance details Defined in Data.Aeson.Types.ToJSON Methods gToJSON :: Options -> ToArgs Encoding One a -> Rec1 f a -> Encoding
ToJSON1 f => GToJSON Value One (Rec1 f) |
Instance details Defined in Data.Aeson.Types.ToJSON Methods gToJSON :: Options -> ToArgs Value One a -> Rec1 f a -> Value
ToJSON a => GToJSON Encoding arity (K1 i a :: Type -> Type) |
Instance details Defined in Data.Aeson.Types.ToJSON Methods gToJSON :: Options -> ToArgs Encoding arity a0 -> K1 i a a0 -> Encoding
(EncodeProduct arity a, EncodeProduct arity b) => GToJSON Encoding arity (a :*: b) |
Instance details Defined in Data.Aeson.Types.ToJSON Methods gToJSON :: Options -> ToArgs Encoding arity a0 -> (a :*: b) a0 -> Encoding
ToJSON a => GToJSON Value arity (K1 i a :: Type -> Type) |
Instance details Defined in Data.Aeson.Types.ToJSON Methods gToJSON :: Options -> ToArgs Value arity a0 -> K1 i a a0 -> Value
(WriteProduct arity a, WriteProduct arity b, ProductSize a, ProductSize b) => GToJSON Value arity (a :*: b) |
Instance details Defined in Data.Aeson.Types.ToJSON Methods gToJSON :: Options -> ToArgs Value arity a0 -> (a :*: b) a0 -> Value
(ToJSON1 f, GToJSON Encoding One g) => GToJSON Encoding One (f :.: g) |
Instance details Defined in Data.Aeson.Types.ToJSON Methods gToJSON :: Options -> ToArgs Encoding One a -> (f :.: g) a -> Encoding
(ToJSON1 f, GToJSON Value One g) => GToJSON Value One (f :.: g) |
Instance details Defined in Data.Aeson.Types.ToJSON Methods gToJSON :: Options -> ToArgs Value One a -> (f :.: g) a -> Value
FromPairs Value (DList Pair) |
Instance details Defined in Data.Aeson.Types.ToJSON Methods fromPairs :: DList Pair -> Value
v ~ Value => KeyValuePair v (DList Pair) |
Instance details Defined in Data.Aeson.Types.ToJSON Methods pair :: String -> v -> DList Pair
(GToJSON Encoding arity a, ConsToJSON Encoding arity a, Constructor c) => SumToJSON' TwoElemArray Encoding arity (C1 c a) |
Instance details Defined in Data.Aeson.Types.ToJSON Methods sumToJSON' :: Options -> ToArgs Encoding arity a0 -> C1 c a a0 -> Tagged TwoElemArray Encoding
(GToJSON Value arity a, ConsToJSON Value arity a, Constructor c) => SumToJSON' TwoElemArray Value arity (C1 c a) |
Instance details Defined in Data.Aeson.Types.ToJSON Methods sumToJSON' :: Options -> ToArgs Value arity a0 -> C1 c a a0 -> Tagged TwoElemArray Value
type Rep Value |

Instance details

Defined in Data.Aeson.Types.Internal

type Rep Value = D1 ('MetaData "Value" "Data.Aeson.Types.Internal" "aeson-1.4.7.1-LcFT4XRNxNk1GX4d6qN7FX" 'False) ((C1 ('MetaCons "Object" 'PrefixI 'False) (S1 ('MetaSel ('Nothing :: Maybe Symbol) 'NoSourceUnpackedness 'SourceStrict 'DecidedStrict) (Rec0 Object)) :+: (C1 ('MetaCons "Array" 'PrefixI 'False) (S1 ('MetaSel ('Nothing :: Maybe Symbol) 'NoSourceUnpackedness 'SourceStrict 'DecidedStrict) (Rec0 Array)) :+: C1 ('MetaCons "String" 'PrefixI 'False) (S1 ('MetaSel ('Nothing :: Maybe Symbol) 'NoSourceUnpackedness 'SourceStrict 'DecidedStrict) (Rec0 Text)))) :+: (C1 ('MetaCons "Number" 'PrefixI 'False) (S1 ('MetaSel ('Nothing :: Maybe Symbol) 'NoSourceUnpackedness 'SourceStrict 'DecidedStrict) (Rec0 Scientific)) :+: (C1 ('MetaCons "Bool" 'PrefixI 'False) (S1 ('MetaSel ('Nothing :: Maybe Symbol) 'NoSourceUnpackedness 'SourceStrict 'DecidedStrict) (Rec0 Bool)) :+: C1 ('MetaCons "Null" 'PrefixI 'False) (U1 :: Type -> Type))))

type Encoding = Encoding' Value Source #

Often used synonym for `Encoding'`.

fromEncoding :: Encoding' tag -> Builder Source #

Acquire the underlying bytestring builder.

type Array = Vector Value Source #

A JSON "array" (sequence).

type Object = HashMap Text Value Source #

A JSON "object" (key/value map).

# Convenience types

newtype DotNetTime Source #

A newtype wrapper for `UTCTime` that uses the same non-standard serialization format as Microsoft .NET, whose System.DateTime type is by default serialized to JSON as in the following example:

    /Date(1302547608878)/

The number represents milliseconds since the Unix epoch.

Constructors

DotNetTime |

Fields

- fromDotNetTime :: UTCTime

  Acquire the underlying value.

#### Instances

Instances details

Eq DotNetTime |
Instance details Defined in Data.Aeson.Types.Internal Methods (==) :: DotNetTime -> DotNetTime -> Bool (/=) :: DotNetTime -> DotNetTime -> Bool
Ord DotNetTime |
Instance details Defined in Data.Aeson.Types.Internal Methods compare :: DotNetTime -> DotNetTime -> Ordering (<) :: DotNetTime -> DotNetTime -> Bool (<=) :: DotNetTime -> DotNetTime -> Bool (>) :: DotNetTime -> DotNetTime -> Bool (>=) :: DotNetTime -> DotNetTime -> Bool max :: DotNetTime -> DotNetTime -> DotNetTime min :: DotNetTime -> DotNetTime -> DotNetTime
Read DotNetTime |
Instance details Defined in Data.Aeson.Types.Internal Methods readsPrec :: Int -> ReadS DotNetTime # readList :: ReadS [DotNetTime] # readPrec :: ReadPrec DotNetTime # readListPrec :: ReadPrec [DotNetTime] #
Show DotNetTime |
Instance details Defined in Data.Aeson.Types.Internal Methods showsPrec :: Int -> DotNetTime -> ShowS show :: DotNetTime -> String showList :: [DotNetTime] -> ShowS
ToJSON DotNetTime |
Instance details Defined in Data.Aeson.Types.ToJSON Methods toJSON :: DotNetTime -> Value Source # toEncoding :: DotNetTime -> Encoding Source # toJSONList :: [DotNetTime] -> Value Source # toEncodingList :: [DotNetTime] -> Encoding Source #
FromJSON DotNetTime |
Instance details Defined in Data.Aeson.Types.FromJSON Methods parseJSON :: Value -> Parser DotNetTime Source # parseJSONList :: Value -> Parser [DotNetTime] Source #
FormatTime DotNetTime |
Instance details Defined in Data.Aeson.Types.Internal Methods formatCharacter :: Bool -> Char -> Maybe (FormatOptions -> DotNetTime -> String)

# Type conversion

class FromJSON a where Source #

A type that can be converted from JSON, with the possibility of failure.

In many cases, you can get the compiler to generate parsing code for you (see below). To begin, let's cover writing an instance by hand.

There are various reasons a conversion could fail. For example, an `Object` could be missing a required key, an `Array` could be of the wrong size, or a value could be of an incompatible type.

The basic ways to signal a failed conversion are as follows:

- `fail` yields a custom error message: it is the recommended way of reporting a failure;
- `empty` (or `mzero`) is uninformative: use it when the error is meant to be caught by some `(`<|>`)`;
- `typeMismatch` can be used to report a failure when the encountered value is not of the expected JSON type; `unexpected` is an appropriate alternative when more than one type may be expected, or to keep the expected type implicit.

`prependFailure` (or `modifyFailure`) add more information to a parser's error messages.

An example type and instance using `typeMismatch` and `prependFailure`:

    -- Allow ourselves to write Text literals.
    {-# LANGUAGE OverloadedStrings #-}

    data Coord = Coord { x :: Double, y :: Double }

    instance FromJSON Coord where
        parseJSON (Object v) = Coord
            <$> v .: "x"
            <*> v .: "y"

        -- We do not expect a non-Object value here.
        -- We could use empty to fail, but typeMismatch
        -- gives a much more informative error message.
        parseJSON invalid    =
            prependFailure "parsing Coord failed, "
                (typeMismatch "Object" invalid)

For this common case of only being concerned with a single type of JSON value, the functions `withObject`, `withScientific`, etc. are provided. Their use is to be preferred when possible, since they are more terse. Using `withObject`, we can rewrite the above instance (assuming the same language extension and data type) as:

    instance FromJSON Coord where
        parseJSON = withObject "Coord" $ \v -> Coord
            <$> v .: "x"
            <*> v .: "y"

Instead of manually writing your `FromJSON` instance, there are two options to do it automatically:

- Data.Aeson.TH provides Template Haskell functions which will derive an instance at compile time. The generated instance is optimized for your type so it will probably be more efficient than the following option.
- The compiler can provide a default generic implementation for `parseJSON`.

To use the second, simply add a `deriving `Generic`` clause to your datatype and declare a `FromJSON` instance for your datatype without giving a definition for `parseJSON`.

For example, the previous example can be simplified to just:

    {-# LANGUAGE DeriveGeneric #-}

    import GHC.Generics

    data Coord = Coord { x :: Double, y :: Double } deriving Generic

    instance FromJSON Coord

The default implementation will be equivalent to `parseJSON = `genericParseJSON` `defaultOptions``; if you need different options, you can customize the generic decoding by defining:

    customOptions = defaultOptions
                    { fieldLabelModifier = map toUpper
                    }

    instance FromJSON Coord where
        parseJSON = genericParseJSON customOptions

Minimal complete definition

Nothing

Methods

parseJSON :: Value -> Parser a Source #

parseJSONList :: Value -> Parser [a] Source #

#### Instances

Instances details

FromJSON Bool |
Instance details Defined in Data.Aeson.Types.FromJSON Methods parseJSON :: Value -> Parser Bool Source # parseJSONList :: Value -> Parser [Bool] Source #
FromJSON Char |
Instance details Defined in Data.Aeson.Types.FromJSON Methods parseJSON :: Value -> Parser Char Source # parseJSONList :: Value -> Parser [Char] Source #
FromJSON Double |
Instance details Defined in Data.Aeson.Types.FromJSON Methods parseJSON :: Value -> Parser Double Source # parseJSONList :: Value -> Parser [Double] Source #
FromJSON Float |
Instance details Defined in Data.Aeson.Types.FromJSON Methods parseJSON :: Value -> Parser Float Source # parseJSONList :: Value -> Parser [Float] Source #
FromJSON Int |
Instance details Defined in Data.Aeson.Types.FromJSON Methods parseJSON :: Value -> Parser Int Source # parseJSONList :: Value -> Parser [Int] Source #
FromJSON Int8 |
Instance details Defined in Data.Aeson.Types.FromJSON Methods parseJSON :: Value -> Parser Int8 Source # parseJSONList :: Value -> Parser [Int8] Source #
FromJSON Int16 |
Instance details Defined in Data.Aeson.Types.FromJSON Methods parseJSON :: Value -> Parser Int16 Source # parseJSONList :: Value -> Parser [Int16] Source #
FromJSON Int32 |
Instance details Defined in Data.Aeson.Types.FromJSON Methods parseJSON :: Value -> Parser Int32 Source # parseJSONList :: Value -> Parser [Int32] Source #
FromJSON Int64 |
Instance details Defined in Data.Aeson.Types.FromJSON Methods parseJSON :: Value -> Parser Int64 Source # parseJSONList :: Value -> Parser [Int64] Source #
FromJSON Integer | This instance includes a bounds check to prevent maliciously large inputs to fill up the memory of the target system. You can newtype `Scientific` and provide your own instance using `withScientific` if you want to allow larger inputs.
Instance details Defined in Data.Aeson.Types.FromJSON Methods parseJSON :: Value -> Parser Integer Source # parseJSONList :: Value -> Parser [Integer] Source #
FromJSON Natural |
Instance details Defined in Data.Aeson.Types.FromJSON Methods parseJSON :: Value -> Parser Natural Source # parseJSONList :: Value -> Parser [Natural] Source #
FromJSON Ordering |
Instance details Defined in Data.Aeson.Types.FromJSON Methods parseJSON :: Value -> Parser Ordering Source # parseJSONList :: Value -> Parser [Ordering] Source #
FromJSON Word |
Instance details Defined in Data.Aeson.Types.FromJSON Methods parseJSON :: Value -> Parser Word Source # parseJSONList :: Value -> Parser [Word] Source #
FromJSON Word8 |
Instance details Defined in Data.Aeson.Types.FromJSON Methods parseJSON :: Value -> Parser Word8 Source # parseJSONList :: Value -> Parser [Word8] Source #
FromJSON Word16 |
Instance details Defined in Data.Aeson.Types.FromJSON Methods parseJSON :: Value -> Parser Word16 Source # parseJSONList :: Value -> Parser [Word16] Source #
FromJSON Word32 |
Instance details Defined in Data.Aeson.Types.FromJSON Methods parseJSON :: Value -> Parser Word32 Source # parseJSONList :: Value -> Parser [Word32] Source #
FromJSON Word64 |
Instance details Defined in Data.Aeson.Types.FromJSON Methods parseJSON :: Value -> Parser Word64 Source # parseJSONList :: Value -> Parser [Word64] Source #
FromJSON () |
Instance details Defined in Data.Aeson.Types.FromJSON Methods parseJSON :: Value -> Parser () Source # parseJSONList :: Value -> Parser [()] Source #
FromJSON Scientific |
Instance details Defined in Data.Aeson.Types.FromJSON Methods parseJSON :: Value -> Parser Scientific Source # parseJSONList :: Value -> Parser [Scientific] Source #
FromJSON Text |
Instance details Defined in Data.Aeson.Types.FromJSON Methods parseJSON :: Value -> Parser Text Source # parseJSONList :: Value -> Parser [Text] Source #
FromJSON UTCTime |
Instance details Defined in Data.Aeson.Types.FromJSON Methods parseJSON :: Value -> Parser UTCTime Source # parseJSONList :: Value -> Parser [UTCTime] Source #
FromJSON Value |
Instance details Defined in Data.Aeson.Types.FromJSON Methods parseJSON :: Value -> Parser Value Source # parseJSONList :: Value -> Parser [Value] Source #
FromJSON DotNetTime |
Instance details Defined in Data.Aeson.Types.FromJSON Methods parseJSON :: Value -> Parser DotNetTime Source # parseJSONList :: Value -> Parser [DotNetTime] Source #
FromJSON Text |
Instance details Defined in Data.Aeson.Types.FromJSON Methods parseJSON :: Value -> Parser Text Source # parseJSONList :: Value -> Parser [Text] Source #
FromJSON Void |
Instance details Defined in Data.Aeson.Types.FromJSON Methods parseJSON :: Value -> Parser Void Source # parseJSONList :: Value -> Parser [Void] Source #
FromJSON Version |
Instance details Defined in Data.Aeson.Types.FromJSON Methods parseJSON :: Value -> Parser Version Source # parseJSONList :: Value -> Parser [Version] Source #
FromJSON Day |
Instance details Defined in Data.Aeson.Types.FromJSON Methods parseJSON :: Value -> Parser Day Source # parseJSONList :: Value -> Parser [Day] Source #
FromJSON DiffTime | This instance includes a bounds check to prevent maliciously large inputs to fill up the memory of the target system. You can newtype `Scientific` and provide your own instance using `withScientific` if you want to allow larger inputs.
Instance details Defined in Data.Aeson.Types.FromJSON Methods parseJSON :: Value -> Parser DiffTime Source # parseJSONList :: Value -> Parser [DiffTime] Source #
FromJSON SystemTime |
Instance details Defined in Data.Aeson.Types.FromJSON Methods parseJSON :: Value -> Parser SystemTime Source # parseJSONList :: Value -> Parser [SystemTime] Source #
FromJSON CalendarDiffDays |
Instance details Defined in Data.Aeson.Types.FromJSON Methods parseJSON :: Value -> Parser CalendarDiffDays Source # parseJSONList :: Value -> Parser [CalendarDiffDays] Source #
FromJSON CalendarDiffTime |
Instance details Defined in Data.Aeson.Types.FromJSON Methods parseJSON :: Value -> Parser CalendarDiffTime Source # parseJSONList :: Value -> Parser [CalendarDiffTime] Source #
FromJSON DayOfWeek |
Instance details Defined in Data.Aeson.Types.FromJSON Methods parseJSON :: Value -> Parser DayOfWeek Source # parseJSONList :: Value -> Parser [DayOfWeek] Source #
FromJSON LocalTime |
Instance details Defined in Data.Aeson.Types.FromJSON Methods parseJSON :: Value -> Parser LocalTime Source # parseJSONList :: Value -> Parser [LocalTime] Source #
FromJSON NominalDiffTime | This instance includes a bounds check to prevent maliciously large inputs to fill up the memory of the target system. You can newtype `Scientific` and provide your own instance using `withScientific` if you want to allow larger inputs.
Instance details Defined in Data.Aeson.Types.FromJSON Methods parseJSON :: Value -> Parser NominalDiffTime Source # parseJSONList :: Value -> Parser [NominalDiffTime] Source #
FromJSON TimeOfDay |
Instance details Defined in Data.Aeson.Types.FromJSON Methods parseJSON :: Value -> Parser TimeOfDay Source # parseJSONList :: Value -> Parser [TimeOfDay] Source #

FromJSON ZonedTime

Supported string formats:

`YYYY-MM-DD HH:MM Z` `YYYY-MM-DD HH:MM:SS Z` `YYYY-MM-DD HH:MM:SS.SSS Z`

The first space may instead be a `T`, and the second space is optional. The `Z` represents UTC. The `Z` may be replaced with a time zone offset of the form `+0000` or `-08:00`, where the first two digits are hours, the `:` is optional and the second two digits (also optional) are minutes.

Instance details Defined in Data.Aeson.Types.FromJSON Methods parseJSON :: Value -> Parser ZonedTime Source # parseJSONList :: Value -> Parser [ZonedTime] Source #
FromJSON CTime |
Instance details Defined in Data.Aeson.Types.FromJSON Methods parseJSON :: Value -> Parser CTime Source # parseJSONList :: Value -> Parser [CTime] Source #
FromJSON IntSet |
Instance details Defined in Data.Aeson.Types.FromJSON Methods parseJSON :: Value -> Parser IntSet Source # parseJSONList :: Value -> Parser [IntSet] Source #
FromJSON UUID |
Instance details Defined in Data.Aeson.Types.FromJSON Methods parseJSON :: Value -> Parser UUID Source # parseJSONList :: Value -> Parser [UUID] Source #
FromJSON a => FromJSON [a] |
Instance details Defined in Data.Aeson.Types.FromJSON Methods parseJSON :: Value -> Parser [a] Source # parseJSONList :: Value -> Parser [[a]] Source #
FromJSON a => FromJSON (Maybe a) |
Instance details Defined in Data.Aeson.Types.FromJSON Methods parseJSON :: Value -> Parser (Maybe a) Source # parseJSONList :: Value -> Parser [Maybe a] Source #
(FromJSON a, Integral a) => FromJSON (Ratio a) |
Instance details Defined in Data.Aeson.Types.FromJSON Methods parseJSON :: Value -> Parser (Ratio a) Source # parseJSONList :: Value -> Parser [Ratio a] Source #
FromJSON a => FromJSON (Identity a) |
Instance details Defined in Data.Aeson.Types.FromJSON Methods parseJSON :: Value -> Parser (Identity a) Source # parseJSONList :: Value -> Parser [Identity a] Source #
FromJSON a => FromJSON (WrappedMonoid a) |
Instance details Defined in Data.Aeson.Types.FromJSON Methods parseJSON :: Value -> Parser (WrappedMonoid a) Source # parseJSONList :: Value -> Parser [WrappedMonoid a] Source #
FromJSON a => FromJSON (Option a) |
Instance details Defined in Data.Aeson.Types.FromJSON Methods parseJSON :: Value -> Parser (Option a) Source # parseJSONList :: Value -> Parser [Option a] Source #
FromJSON a => FromJSON (Min a) |
Instance details Defined in Data.Aeson.Types.FromJSON Methods parseJSON :: Value -> Parser (Min a) Source # parseJSONList :: Value -> Parser [Min a] Source #
FromJSON a => FromJSON (Max a) |
Instance details Defined in Data.Aeson.Types.FromJSON Methods parseJSON :: Value -> Parser (Max a) Source # parseJSONList :: Value -> Parser [Max a] Source #
FromJSON a => FromJSON (Last a) |
Instance details Defined in Data.Aeson.Types.FromJSON Methods parseJSON :: Value -> Parser (Last a) Source # parseJSONList :: Value -> Parser [Last a] Source #
FromJSON a => FromJSON (First a) |
Instance details Defined in Data.Aeson.Types.FromJSON Methods parseJSON :: Value -> Parser (First a) Source # parseJSONList :: Value -> Parser [First a] Source #
FromJSON a => FromJSON (Last a) |
Instance details Defined in Data.Aeson.Types.FromJSON Methods parseJSON :: Value -> Parser (Last a) Source # parseJSONList :: Value -> Parser [Last a] Source #
FromJSON a => FromJSON (First a) |
Instance details Defined in Data.Aeson.Types.FromJSON Methods parseJSON :: Value -> Parser (First a) Source # parseJSONList :: Value -> Parser [First a] Source #
FromJSON a => FromJSON (Dual a) |
Instance details Defined in Data.Aeson.Types.FromJSON Methods parseJSON :: Value -> Parser (Dual a) Source # parseJSONList :: Value -> Parser [Dual a] Source #
FromJSON a => FromJSON (NonEmpty a) |
Instance details Defined in Data.Aeson.Types.FromJSON Methods parseJSON :: Value -> Parser (NonEmpty a) Source # parseJSONList :: Value -> Parser [NonEmpty a] Source #
(Eq a, Hashable a, FromJSON a) => FromJSON (HashSet a) |
Instance details Defined in Data.Aeson.Types.FromJSON Methods parseJSON :: Value -> Parser (HashSet a) Source # parseJSONList :: Value -> Parser [HashSet a] Source #
(Vector Vector a, FromJSON a) => FromJSON (Vector a) |
Instance details Defined in Data.Aeson.Types.FromJSON Methods parseJSON :: Value -> Parser (Vector a) Source # parseJSONList :: Value -> Parser [Vector a] Source #
(Storable a, FromJSON a) => FromJSON (Vector a) |
Instance details Defined in Data.Aeson.Types.FromJSON Methods parseJSON :: Value -> Parser (Vector a) Source # parseJSONList :: Value -> Parser [Vector a] Source #
(Prim a, FromJSON a) => FromJSON (Vector a) |
Instance details Defined in Data.Aeson.Types.FromJSON Methods parseJSON :: Value -> Parser (Vector a) Source # parseJSONList :: Value -> Parser [Vector a] Source #
FromJSON a => FromJSON (Vector a) |
Instance details Defined in Data.Aeson.Types.FromJSON Methods parseJSON :: Value -> Parser (Vector a) Source # parseJSONList :: Value -> Parser [Vector a] Source #
FromJSON a => FromJSON (Array a) |
Instance details Defined in Data.Aeson.Types.FromJSON Methods parseJSON :: Value -> Parser (Array a) Source # parseJSONList :: Value -> Parser [Array a] Source #
FromJSON a => FromJSON (DList a) |
Instance details Defined in Data.Aeson.Types.FromJSON Methods parseJSON :: Value -> Parser (DList a) Source # parseJSONList :: Value -> Parser [DList a] Source #
FromJSON a => FromJSON (IntMap a) |
Instance details Defined in Data.Aeson.Types.FromJSON Methods parseJSON :: Value -> Parser (IntMap a) Source # parseJSONList :: Value -> Parser [IntMap a] Source #
FromJSON a => FromJSON (Seq a) |
Instance details Defined in Data.Aeson.Types.FromJSON Methods parseJSON :: Value -> Parser (Seq a) Source # parseJSONList :: Value -> Parser [Seq a] Source #
FromJSON v => FromJSON (Tree v) |
Instance details Defined in Data.Aeson.Types.FromJSON Methods parseJSON :: Value -> Parser (Tree v) Source # parseJSONList :: Value -> Parser [Tree v] Source #
HasResolution a => FromJSON (Fixed a) | This instance includes a bounds check to prevent maliciously large inputs to fill up the memory of the target system. You can newtype `Scientific` and provide your own instance using `withScientific` if you want to allow larger inputs.
Instance details Defined in Data.Aeson.Types.FromJSON Methods parseJSON :: Value -> Parser (Fixed a) Source # parseJSONList :: Value -> Parser [Fixed a] Source #
(Prim a, FromJSON a) => FromJSON (PrimArray a) |
Instance details Defined in Data.Aeson.Types.FromJSON Methods parseJSON :: Value -> Parser (PrimArray a) Source # parseJSONList :: Value -> Parser [PrimArray a] Source #
(Ord a, FromJSON a) => FromJSON (Set a) |
Instance details Defined in Data.Aeson.Types.FromJSON Methods parseJSON :: Value -> Parser (Set a) Source # parseJSONList :: Value -> Parser [Set a] Source #
FromJSON a => FromJSON (SmallArray a) |
Instance details Defined in Data.Aeson.Types.FromJSON Methods parseJSON :: Value -> Parser (SmallArray a) Source # parseJSONList :: Value -> Parser [SmallArray a] Source #
(FromJSON a, FromJSON b) => FromJSON (Either a b) |
Instance details Defined in Data.Aeson.Types.FromJSON Methods parseJSON :: Value -> Parser (Either a b) Source # parseJSONList :: Value -> Parser [Either a b] Source #
(FromJSON a, FromJSON b) => FromJSON (a, b) |
Instance details Defined in Data.Aeson.Types.FromJSON Methods parseJSON :: Value -> Parser (a, b) Source # parseJSONList :: Value -> Parser [(a, b)] Source #
(FromJSON v, FromJSONKey k, Eq k, Hashable k) => FromJSON (HashMap k v) |
Instance details Defined in Data.Aeson.Types.FromJSON Methods parseJSON :: Value -> Parser (HashMap k v) Source # parseJSONList :: Value -> Parser [HashMap k v] Source #
(FromJSONKey k, Ord k, FromJSON v) => FromJSON (Map k v) |
Instance details Defined in Data.Aeson.Types.FromJSON Methods parseJSON :: Value -> Parser (Map k v) Source # parseJSONList :: Value -> Parser [Map k v] Source #
FromJSON (Proxy a) |
Instance details Defined in Data.Aeson.Types.FromJSON Methods parseJSON :: Value -> Parser (Proxy a) Source # parseJSONList :: Value -> Parser [Proxy a] Source #
(FromJSON a, FromJSON b, FromJSON c) => FromJSON (a, b, c) |
Instance details Defined in Data.Aeson.Types.FromJSON Methods parseJSON :: Value -> Parser (a, b, c) Source # parseJSONList :: Value -> Parser [(a, b, c)] Source #
FromJSON a => FromJSON (Const a b) |
Instance details Defined in Data.Aeson.Types.FromJSON Methods parseJSON :: Value -> Parser (Const a b) Source # parseJSONList :: Value -> Parser [Const a b] Source #
FromJSON b => FromJSON (Tagged a b) |
Instance details Defined in Data.Aeson.Types.FromJSON Methods parseJSON :: Value -> Parser (Tagged a b) Source # parseJSONList :: Value -> Parser [Tagged a b] Source #
(FromJSON a, FromJSON b, FromJSON c, FromJSON d) => FromJSON (a, b, c, d) |
Instance details Defined in Data.Aeson.Types.FromJSON Methods parseJSON :: Value -> Parser (a, b, c, d) Source # parseJSONList :: Value -> Parser [(a, b, c, d)] Source #
(FromJSON1 f, FromJSON1 g, FromJSON a) => FromJSON (Sum f g a) |
Instance details Defined in Data.Aeson.Types.FromJSON Methods parseJSON :: Value -> Parser (Sum f g a) Source # parseJSONList :: Value -> Parser [Sum f g a] Source #
(FromJSON1 f, FromJSON1 g, FromJSON a) => FromJSON (Product f g a) |
Instance details Defined in Data.Aeson.Types.FromJSON Methods parseJSON :: Value -> Parser (Product f g a) Source # parseJSONList :: Value -> Parser [Product f g a] Source #
(FromJSON a, FromJSON b, FromJSON c, FromJSON d, FromJSON e) => FromJSON (a, b, c, d, e) |
Instance details Defined in Data.Aeson.Types.FromJSON Methods parseJSON :: Value -> Parser (a, b, c, d, e) Source # parseJSONList :: Value -> Parser [(a, b, c, d, e)] Source #
(FromJSON1 f, FromJSON1 g, FromJSON a) => FromJSON (Compose f g a) |
Instance details Defined in Data.Aeson.Types.FromJSON Methods parseJSON :: Value -> Parser (Compose f g a) Source # parseJSONList :: Value -> Parser [Compose f g a] Source #
(FromJSON a, FromJSON b, FromJSON c, FromJSON d, FromJSON e, FromJSON f) => FromJSON (a, b, c, d, e, f) |
Instance details Defined in Data.Aeson.Types.FromJSON Methods parseJSON :: Value -> Parser (a, b, c, d, e, f) Source # parseJSONList :: Value -> Parser [(a, b, c, d, e, f)] Source #
(FromJSON a, FromJSON b, FromJSON c, FromJSON d, FromJSON e, FromJSON f, FromJSON g) => FromJSON (a, b, c, d, e, f, g) |
Instance details Defined in Data.Aeson.Types.FromJSON Methods parseJSON :: Value -> Parser (a, b, c, d, e, f, g) Source # parseJSONList :: Value -> Parser [(a, b, c, d, e, f, g)] Source #
(FromJSON a, FromJSON b, FromJSON c, FromJSON d, FromJSON e, FromJSON f, FromJSON g, FromJSON h) => FromJSON (a, b, c, d, e, f, g, h) |
Instance details Defined in Data.Aeson.Types.FromJSON Methods parseJSON :: Value -> Parser (a, b, c, d, e, f, g, h) Source # parseJSONList :: Value -> Parser [(a, b, c, d, e, f, g, h)] Source #
(FromJSON a, FromJSON b, FromJSON c, FromJSON d, FromJSON e, FromJSON f, FromJSON g, FromJSON h, FromJSON i) => FromJSON (a, b, c, d, e, f, g, h, i) |
Instance details Defined in Data.Aeson.Types.FromJSON Methods parseJSON :: Value -> Parser (a, b, c, d, e, f, g, h, i) Source # parseJSONList :: Value -> Parser [(a, b, c, d, e, f, g, h, i)] Source #
(FromJSON a, FromJSON b, FromJSON c, FromJSON d, FromJSON e, FromJSON f, FromJSON g, FromJSON h, FromJSON i, FromJSON j) => FromJSON (a, b, c, d, e, f, g, h, i, j) |
Instance details Defined in Data.Aeson.Types.FromJSON Methods parseJSON :: Value -> Parser (a, b, c, d, e, f, g, h, i, j) Source # parseJSONList :: Value -> Parser [(a, b, c, d, e, f, g, h, i, j)] Source #
(FromJSON a, FromJSON b, FromJSON c, FromJSON d, FromJSON e, FromJSON f, FromJSON g, FromJSON h, FromJSON i, FromJSON j, FromJSON k) => FromJSON (a, b, c, d, e, f, g, h, i, j, k) |
Instance details Defined in Data.Aeson.Types.FromJSON Methods parseJSON :: Value -> Parser (a, b, c, d, e, f, g, h, i, j, k) Source # parseJSONList :: Value -> Parser [(a, b, c, d, e, f, g, h, i, j, k)] Source #
(FromJSON a, FromJSON b, FromJSON c, FromJSON d, FromJSON e, FromJSON f, FromJSON g, FromJSON h, FromJSON i, FromJSON j, FromJSON k, FromJSON l) => FromJSON (a, b, c, d, e, f, g, h, i, j, k, l) |
Instance details Defined in Data.Aeson.Types.FromJSON Methods parseJSON :: Value -> Parser (a, b, c, d, e, f, g, h, i, j, k, l) Source # parseJSONList :: Value -> Parser [(a, b, c, d, e, f, g, h, i, j, k, l)] Source #
(FromJSON a, FromJSON b, FromJSON c, FromJSON d, FromJSON e, FromJSON f, FromJSON g, FromJSON h, FromJSON i, FromJSON j, FromJSON k, FromJSON l, FromJSON m) => FromJSON (a, b, c, d, e, f, g, h, i, j, k, l, m) |
Instance details Defined in Data.Aeson.Types.FromJSON Methods parseJSON :: Value -> Parser (a, b, c, d, e, f, g, h, i, j, k, l, m) Source # parseJSONList :: Value -> Parser [(a, b, c, d, e, f, g, h, i, j, k, l, m)] Source #
(FromJSON a, FromJSON b, FromJSON c, FromJSON d, FromJSON e, FromJSON f, FromJSON g, FromJSON h, FromJSON i, FromJSON j, FromJSON k, FromJSON l, FromJSON m, FromJSON n) => FromJSON (a, b, c, d, e, f, g, h, i, j, k, l, m, n) |
Instance details Defined in Data.Aeson.Types.FromJSON Methods parseJSON :: Value -> Parser (a, b, c, d, e, f, g, h, i, j, k, l, m, n) Source # parseJSONList :: Value -> Parser [(a, b, c, d, e, f, g, h, i, j, k, l, m, n)] Source #
(FromJSON a, FromJSON b, FromJSON c, FromJSON d, FromJSON e, FromJSON f, FromJSON g, FromJSON h, FromJSON i, FromJSON j, FromJSON k, FromJSON l, FromJSON m, FromJSON n, FromJSON o) => FromJSON (a, b, c, d, e, f, g, h, i, j, k, l, m, n, o) |
Instance details Defined in Data.Aeson.Types.FromJSON Methods parseJSON :: Value -> Parser (a, b, c, d, e, f, g, h, i, j, k, l, m, n, o) Source # parseJSONList :: Value -> Parser [(a, b, c, d, e, f, g, h, i, j, k, l, m, n, o)] Source #

data Result a Source #

The result of running a `Parser`.

Constructors

Error String |
Success a |

#### Instances

Instances details

Monad Result |
Instance details Defined in Data.Aeson.Types.Internal Methods (>>=) :: Result a -> (a -> Result b) -> Result b # (>>) :: Result a -> Result b -> Result b # return :: a -> Result a #
Functor Result |
Instance details Defined in Data.Aeson.Types.Internal Methods fmap :: (a -> b) -> Result a -> Result b # (<$) :: a -> Result b -> Result a #
MonadFail Result |
Instance details Defined in Data.Aeson.Types.Internal Methods fail :: String -> Result a #
Applicative Result |
Instance details Defined in Data.Aeson.Types.Internal Methods pure :: a -> Result a (<*>) :: Result (a -> b) -> Result a -> Result b liftA2 :: (a -> b -> c) -> Result a -> Result b -> Result c (*>) :: Result a -> Result b -> Result b (<*) :: Result a -> Result b -> Result a
Foldable Result |

Instance details

Defined in Data.Aeson.Types.Internal

Methods

fold :: Monoid m => Result m -> m

foldMap :: Monoid m => (a -> m) -> Result a -> m

foldMap' :: Monoid m => (a -> m) -> Result a -> m

foldr :: (a -> b -> b) -> b -> Result a -> b

foldr' :: (a -> b -> b) -> b -> Result a -> b

foldl :: (b -> a -> b) -> b -> Result a -> b

foldl' :: (b -> a -> b) -> b -> Result a -> b

foldr1 :: (a -> a -> a) -> Result a -> a

foldl1 :: (a -> a -> a) -> Result a -> a

toList :: Result a -> [a]

null :: Result a -> Bool

length :: Result a -> Int

elem :: Eq a => a -> Result a -> Bool

maximum :: Ord a => Result a -> a

minimum :: Ord a => Result a -> a

sum :: Num a => Result a -> a

product :: Num a => Result a -> a

Traversable Result |
Instance details Defined in Data.Aeson.Types.Internal Methods traverse :: Applicative f => (a -> f b) -> Result a -> f (Result b) sequenceA :: Applicative f => Result (f a) -> f (Result a) mapM :: Monad m => (a -> m b) -> Result a -> m (Result b) # sequence :: Monad m => Result (m a) -> m (Result a) #
Alternative Result |
Instance details Defined in Data.Aeson.Types.Internal Methods empty :: Result a (<|>) :: Result a -> Result a -> Result a some :: Result a -> Result [a] many :: Result a -> Result [a]
MonadPlus Result |
Instance details Defined in Data.Aeson.Types.Internal Methods mzero :: Result a # mplus :: Result a -> Result a -> Result a #
Eq a => Eq (Result a) |
Instance details Defined in Data.Aeson.Types.Internal Methods (==) :: Result a -> Result a -> Bool (/=) :: Result a -> Result a -> Bool
Show a => Show (Result a) |
Instance details Defined in Data.Aeson.Types.Internal Methods showsPrec :: Int -> Result a -> ShowS show :: Result a -> String showList :: [Result a] -> ShowS
Semigroup (Result a) |
Instance details Defined in Data.Aeson.Types.Internal Methods (<>) :: Result a -> Result a -> Result a # sconcat :: NonEmpty (Result a) -> Result a # stimes :: Integral b => b -> Result a -> Result a #
Monoid (Result a) |
Instance details Defined in Data.Aeson.Types.Internal Methods mempty :: Result a # mappend :: Result a -> Result a -> Result a # mconcat :: [Result a] -> Result a #
NFData a => NFData (Result a) |
Instance details Defined in Data.Aeson.Types.Internal Methods rnf :: Result a -> ()

fromJSON :: FromJSON a => Value -> Result a Source #

Convert a value from JSON, failing if the types do not match.

class ToJSON a where Source #

A type that can be converted to JSON.

Instances in general must specify `toJSON` and should (but don't need to) specify `toEncoding`.

An example type and instance:

    -- Allow ourselves to write Text literals.
    {-# LANGUAGE OverloadedStrings #-}

    data Coord = Coord { x :: Double, y :: Double }

    instance ToJSON Coord where
      toJSON (Coord x y) = object ["x" .= x, "y" .= y]

      toEncoding (Coord x y) = pairs ("x" .= x <> "y" .= y)

Instead of manually writing your `ToJSON` instance, there are two options to do it automatically:

- Data.Aeson.TH provides Template Haskell functions which will derive an instance at compile time. The generated instance is optimized for your type so it will probably be more efficient than the following option.
- The compiler can provide a default generic implementation for `toJSON`.

To use the second, simply add a `deriving `Generic`` clause to your datatype and declare a `ToJSON` instance. If you require nothing other than `defaultOptions`, it is sufficient to write (and this is the only alternative where the default `toJSON` implementation is sufficient):

    {-# LANGUAGE DeriveGeneric #-}

    import GHC.Generics

    data Coord = Coord { x :: Double, y :: Double } deriving Generic

    instance ToJSON Coord where
        toEncoding = genericToEncoding defaultOptions

If on the other hand you wish to customize the generic decoding, you have to implement both methods:

    customOptions = defaultOptions
                    { fieldLabelModifier = map toUpper
                    }

    instance ToJSON Coord where
        toJSON     = genericToJSON customOptions
        toEncoding = genericToEncoding customOptions

Previous versions of this library only had the `toJSON` method. Adding `toEncoding` had two reasons:

1. toEncoding is more efficient for the common case that the output of `toJSON` is directly serialized to a `ByteString`. Further, expressing either method in terms of the other would be non-optimal.
2. The choice of defaults allows a smooth transition for existing users: Existing instances that do not define `toEncoding` still compile and have the correct semantics. This is ensured by making the default implementation of `toEncoding` use `toJSON`. This produces correct results, but since it performs an intermediate conversion to a `Value`, it will be less efficient than directly emitting an `Encoding`. (this also means that specifying nothing more than `instance ToJSON Coord` would be sufficient as a generically decoding instance, but there probably exists no good reason to not specify `toEncoding` in new instances.)

Minimal complete definition

Nothing

Methods

toJSON :: a -> Value Source #

Convert a Haskell value to a JSON-friendly intermediate type.

toEncoding :: a -> Encoding Source #

Encode a Haskell value as JSON.

The default implementation of this method creates an intermediate `Value` using `toJSON`. This provides source-level compatibility for people upgrading from older versions of this library, but obviously offers no performance advantage.

To benefit from direct encoding, you must provide an implementation for this method. The easiest way to do so is by having your types implement `Generic` using the `DeriveGeneric` extension, and then have GHC generate a method body as follows.

    instance ToJSON Coord where
        toEncoding = genericToEncoding defaultOptions

toJSONList :: [a] -> Value Source #

toEncodingList :: [a] -> Encoding Source #

#### Instances

Instances details

ToJSON Bool |
Instance details Defined in Data.Aeson.Types.ToJSON Methods toJSON :: Bool -> Value Source # toEncoding :: Bool -> Encoding Source # toJSONList :: [Bool] -> Value Source # toEncodingList :: [Bool] -> Encoding Source #
ToJSON Char |
Instance details Defined in Data.Aeson.Types.ToJSON Methods toJSON :: Char -> Value Source # toEncoding :: Char -> Encoding Source # toJSONList :: [Char] -> Value Source # toEncodingList :: [Char] -> Encoding Source #
ToJSON Double |
Instance details Defined in Data.Aeson.Types.ToJSON Methods toJSON :: Double -> Value Source # toEncoding :: Double -> Encoding Source # toJSONList :: [Double] -> Value Source # toEncodingList :: [Double] -> Encoding Source #
ToJSON Float |
Instance details Defined in Data.Aeson.Types.ToJSON Methods toJSON :: Float -> Value Source # toEncoding :: Float -> Encoding Source # toJSONList :: [Float] -> Value Source # toEncodingList :: [Float] -> Encoding Source #
ToJSON Int |
Instance details Defined in Data.Aeson.Types.ToJSON Methods toJSON :: Int -> Value Source # toEncoding :: Int -> Encoding Source # toJSONList :: [Int] -> Value Source # toEncodingList :: [Int] -> Encoding Source #
ToJSON Int8 |
Instance details Defined in Data.Aeson.Types.ToJSON Methods toJSON :: Int8 -> Value Source # toEncoding :: Int8 -> Encoding Source # toJSONList :: [Int8] -> Value Source # toEncodingList :: [Int8] -> Encoding Source #
ToJSON Int16 |
Instance details Defined in Data.Aeson.Types.ToJSON Methods toJSON :: Int16 -> Value Source # toEncoding :: Int16 -> Encoding Source # toJSONList :: [Int16] -> Value Source # toEncodingList :: [Int16] -> Encoding Source #
ToJSON Int32 |
Instance details Defined in Data.Aeson.Types.ToJSON Methods toJSON :: Int32 -> Value Source # toEncoding :: Int32 -> Encoding Source # toJSONList :: [Int32] -> Value Source # toEncodingList :: [Int32] -> Encoding Source #
ToJSON Int64 |
Instance details Defined in Data.Aeson.Types.ToJSON Methods toJSON :: Int64 -> Value Source # toEncoding :: Int64 -> Encoding Source # toJSONList :: [Int64] -> Value Source # toEncodingList :: [Int64] -> Encoding Source #
ToJSON Integer |
Instance details Defined in Data.Aeson.Types.ToJSON Methods toJSON :: Integer -> Value Source # toEncoding :: Integer -> Encoding Source # toJSONList :: [Integer] -> Value Source # toEncodingList :: [Integer] -> Encoding Source #
ToJSON Natural |
Instance details Defined in Data.Aeson.Types.ToJSON Methods toJSON :: Natural -> Value Source # toEncoding :: Natural -> Encoding Source # toJSONList :: [Natural] -> Value Source # toEncodingList :: [Natural] -> Encoding Source #
ToJSON Ordering |
Instance details Defined in Data.Aeson.Types.ToJSON Methods toJSON :: Ordering -> Value Source # toEncoding :: Ordering -> Encoding Source # toJSONList :: [Ordering] -> Value Source # toEncodingList :: [Ordering] -> Encoding Source #
ToJSON Word |
Instance details Defined in Data.Aeson.Types.ToJSON Methods toJSON :: Word -> Value Source # toEncoding :: Word -> Encoding Source # toJSONList :: [Word] -> Value Source # toEncodingList :: [Word] -> Encoding Source #
ToJSON Word8 |
Instance details Defined in Data.Aeson.Types.ToJSON Methods toJSON :: Word8 -> Value Source # toEncoding :: Word8 -> Encoding Source # toJSONList :: [Word8] -> Value Source # toEncodingList :: [Word8] -> Encoding Source #
ToJSON Word16 |
Instance details Defined in Data.Aeson.Types.ToJSON Methods toJSON :: Word16 -> Value Source # toEncoding :: Word16 -> Encoding Source # toJSONList :: [Word16] -> Value Source # toEncodingList :: [Word16] -> Encoding Source #
ToJSON Word32 |
Instance details Defined in Data.Aeson.Types.ToJSON Methods toJSON :: Word32 -> Value Source # toEncoding :: Word32 -> Encoding Source # toJSONList :: [Word32] -> Value Source # toEncodingList :: [Word32] -> Encoding Source #
ToJSON Word64 |
Instance details Defined in Data.Aeson.Types.ToJSON Methods toJSON :: Word64 -> Value Source # toEncoding :: Word64 -> Encoding Source # toJSONList :: [Word64] -> Value Source # toEncodingList :: [Word64] -> Encoding Source #
ToJSON () |
Instance details Defined in Data.Aeson.Types.ToJSON Methods toJSON :: () -> Value Source # toEncoding :: () -> Encoding Source # toJSONList :: [()] -> Value Source # toEncodingList :: [()] -> Encoding Source #
ToJSON Scientific |
Instance details Defined in Data.Aeson.Types.ToJSON Methods toJSON :: Scientific -> Value Source # toEncoding :: Scientific -> Encoding Source # toJSONList :: [Scientific] -> Value Source # toEncodingList :: [Scientific] -> Encoding Source #
ToJSON Text |
Instance details Defined in Data.Aeson.Types.ToJSON Methods toJSON :: Text -> Value Source # toEncoding :: Text -> Encoding Source # toJSONList :: [Text] -> Value Source # toEncodingList :: [Text] -> Encoding Source #
ToJSON UTCTime |
Instance details Defined in Data.Aeson.Types.ToJSON Methods toJSON :: UTCTime -> Value Source # toEncoding :: UTCTime -> Encoding Source # toJSONList :: [UTCTime] -> Value Source # toEncodingList :: [UTCTime] -> Encoding Source #
ToJSON Value |
Instance details Defined in Data.Aeson.Types.ToJSON Methods toJSON :: Value -> Value Source # toEncoding :: Value -> Encoding Source # toJSONList :: [Value] -> Value Source # toEncodingList :: [Value] -> Encoding Source #
ToJSON DotNetTime |
Instance details Defined in Data.Aeson.Types.ToJSON Methods toJSON :: DotNetTime -> Value Source # toEncoding :: DotNetTime -> Encoding Source # toJSONList :: [DotNetTime] -> Value Source # toEncodingList :: [DotNetTime] -> Encoding Source #
ToJSON Text |
Instance details Defined in Data.Aeson.Types.ToJSON Methods toJSON :: Text -> Value Source # toEncoding :: Text -> Encoding Source # toJSONList :: [Text] -> Value Source # toEncodingList :: [Text] -> Encoding Source #
ToJSON Number |
Instance details Defined in Data.Aeson.Types.ToJSON Methods toJSON :: Number -> Value Source # toEncoding :: Number -> Encoding Source # toJSONList :: [Number] -> Value Source # toEncodingList :: [Number] -> Encoding Source #
ToJSON Void |
Instance details Defined in Data.Aeson.Types.ToJSON Methods toJSON :: Void -> Value Source # toEncoding :: Void -> Encoding Source # toJSONList :: [Void] -> Value Source # toEncodingList :: [Void] -> Encoding Source #
ToJSON Version |
Instance details Defined in Data.Aeson.Types.ToJSON Methods toJSON :: Version -> Value Source # toEncoding :: Version -> Encoding Source # toJSONList :: [Version] -> Value Source # toEncodingList :: [Version] -> Encoding Source #
ToJSON Day |
Instance details Defined in Data.Aeson.Types.ToJSON Methods toJSON :: Day -> Value Source # toEncoding :: Day -> Encoding Source # toJSONList :: [Day] -> Value Source # toEncodingList :: [Day] -> Encoding Source #
ToJSON DiffTime |
Instance details Defined in Data.Aeson.Types.ToJSON Methods toJSON :: DiffTime -> Value Source # toEncoding :: DiffTime -> Encoding Source # toJSONList :: [DiffTime] -> Value Source # toEncodingList :: [DiffTime] -> Encoding Source #
ToJSON SystemTime | Encoded as number
Instance details Defined in Data.Aeson.Types.ToJSON Methods toJSON :: SystemTime -> Value Source # toEncoding :: SystemTime -> Encoding Source # toJSONList :: [SystemTime] -> Value Source # toEncodingList :: [SystemTime] -> Encoding Source #
ToJSON CalendarDiffDays |
Instance details Defined in Data.Aeson.Types.ToJSON Methods toJSON :: CalendarDiffDays -> Value Source # toEncoding :: CalendarDiffDays -> Encoding Source # toJSONList :: [CalendarDiffDays] -> Value Source # toEncodingList :: [CalendarDiffDays] -> Encoding Source #
ToJSON CalendarDiffTime |
Instance details Defined in Data.Aeson.Types.ToJSON Methods toJSON :: CalendarDiffTime -> Value Source # toEncoding :: CalendarDiffTime -> Encoding Source # toJSONList :: [CalendarDiffTime] -> Value Source # toEncodingList :: [CalendarDiffTime] -> Encoding Source #
ToJSON DayOfWeek |
Instance details Defined in Data.Aeson.Types.ToJSON Methods toJSON :: DayOfWeek -> Value Source # toEncoding :: DayOfWeek -> Encoding Source # toJSONList :: [DayOfWeek] -> Value Source # toEncodingList :: [DayOfWeek] -> Encoding Source #
ToJSON LocalTime |
Instance details Defined in Data.Aeson.Types.ToJSON Methods toJSON :: LocalTime -> Value Source # toEncoding :: LocalTime -> Encoding Source # toJSONList :: [LocalTime] -> Value Source # toEncodingList :: [LocalTime] -> Encoding Source #
ToJSON NominalDiffTime |
Instance details Defined in Data.Aeson.Types.ToJSON Methods toJSON :: NominalDiffTime -> Value Source # toEncoding :: NominalDiffTime -> Encoding Source # toJSONList :: [NominalDiffTime] -> Value Source # toEncodingList :: [NominalDiffTime] -> Encoding Source #
ToJSON TimeOfDay |
Instance details Defined in Data.Aeson.Types.ToJSON Methods toJSON :: TimeOfDay -> Value Source # toEncoding :: TimeOfDay -> Encoding Source # toJSONList :: [TimeOfDay] -> Value Source # toEncodingList :: [TimeOfDay] -> Encoding Source #
ToJSON ZonedTime |
Instance details Defined in Data.Aeson.Types.ToJSON Methods toJSON :: ZonedTime -> Value Source # toEncoding :: ZonedTime -> Encoding Source # toJSONList :: [ZonedTime] -> Value Source # toEncodingList :: [ZonedTime] -> Encoding Source #
ToJSON CTime |
Instance details Defined in Data.Aeson.Types.ToJSON Methods toJSON :: CTime -> Value Source # toEncoding :: CTime -> Encoding Source # toJSONList :: [CTime] -> Value Source # toEncodingList :: [CTime] -> Encoding Source #
ToJSON IntSet |
Instance details Defined in Data.Aeson.Types.ToJSON Methods toJSON :: IntSet -> Value Source # toEncoding :: IntSet -> Encoding Source # toJSONList :: [IntSet] -> Value Source # toEncodingList :: [IntSet] -> Encoding Source #
ToJSON UUID |
Instance details Defined in Data.Aeson.Types.ToJSON Methods toJSON :: UUID -> Value Source # toEncoding :: UUID -> Encoding Source # toJSONList :: [UUID] -> Value Source # toEncodingList :: [UUID] -> Encoding Source #
ToJSON a => ToJSON [a] |
Instance details Defined in Data.Aeson.Types.ToJSON Methods toJSON :: [a] -> Value Source # toEncoding :: [a] -> Encoding Source # toJSONList :: [[a]] -> Value Source # toEncodingList :: [[a]] -> Encoding Source #
ToJSON a => ToJSON (Maybe a) |
Instance details Defined in Data.Aeson.Types.ToJSON Methods toJSON :: Maybe a -> Value Source # toEncoding :: Maybe a -> Encoding Source # toJSONList :: [Maybe a] -> Value Source # toEncodingList :: [Maybe a] -> Encoding Source #
(ToJSON a, Integral a) => ToJSON (Ratio a) |
Instance details Defined in Data.Aeson.Types.ToJSON Methods toJSON :: Ratio a -> Value Source # toEncoding :: Ratio a -> Encoding Source # toJSONList :: [Ratio a] -> Value Source # toEncodingList :: [Ratio a] -> Encoding Source #
ToJSON a => ToJSON (Identity a) |
Instance details Defined in Data.Aeson.Types.ToJSON Methods toJSON :: Identity a -> Value Source # toEncoding :: Identity a -> Encoding Source # toJSONList :: [Identity a] -> Value Source # toEncodingList :: [Identity a] -> Encoding Source #
ToJSON a => ToJSON (WrappedMonoid a) |
Instance details Defined in Data.Aeson.Types.ToJSON Methods toJSON :: WrappedMonoid a -> Value Source # toEncoding :: WrappedMonoid a -> Encoding Source # toJSONList :: [WrappedMonoid a] -> Value Source # toEncodingList :: [WrappedMonoid a] -> Encoding Source #
ToJSON a => ToJSON (Option a) |
Instance details Defined in Data.Aeson.Types.ToJSON Methods toJSON :: Option a -> Value Source # toEncoding :: Option a -> Encoding Source # toJSONList :: [Option a] -> Value Source # toEncodingList :: [Option a] -> Encoding Source #
ToJSON a => ToJSON (Min a) |
Instance details Defined in Data.Aeson.Types.ToJSON Methods toJSON :: Min a -> Value Source # toEncoding :: Min a -> Encoding Source # toJSONList :: [Min a] -> Value Source # toEncodingList :: [Min a] -> Encoding Source #
ToJSON a => ToJSON (Max a) |
Instance details Defined in Data.Aeson.Types.ToJSON Methods toJSON :: Max a -> Value Source # toEncoding :: Max a -> Encoding Source # toJSONList :: [Max a] -> Value Source # toEncodingList :: [Max a] -> Encoding Source #
ToJSON a => ToJSON (Last a) |
Instance details Defined in Data.Aeson.Types.ToJSON Methods toJSON :: Last a -> Value Source # toEncoding :: Last a -> Encoding Source # toJSONList :: [Last a] -> Value Source # toEncodingList :: [Last a] -> Encoding Source #
ToJSON a => ToJSON (First a) |
Instance details Defined in Data.Aeson.Types.ToJSON Methods toJSON :: First a -> Value Source # toEncoding :: First a -> Encoding Source # toJSONList :: [First a] -> Value Source # toEncodingList :: [First a] -> Encoding Source #
ToJSON a => ToJSON (Last a) |
Instance details Defined in Data.Aeson.Types.ToJSON Methods toJSON :: Last a -> Value Source # toEncoding :: Last a -> Encoding Source # toJSONList :: [Last a] -> Value Source # toEncodingList :: [Last a] -> Encoding Source #
ToJSON a => ToJSON (First a) |
Instance details Defined in Data.Aeson.Types.ToJSON Methods toJSON :: First a -> Value Source # toEncoding :: First a -> Encoding Source # toJSONList :: [First a] -> Value Source # toEncodingList :: [First a] -> Encoding Source #
ToJSON a => ToJSON (Dual a) |
Instance details Defined in Data.Aeson.Types.ToJSON Methods toJSON :: Dual a -> Value Source # toEncoding :: Dual a -> Encoding Source # toJSONList :: [Dual a] -> Value Source # toEncodingList :: [Dual a] -> Encoding Source #
ToJSON a => ToJSON (NonEmpty a) |
Instance details Defined in Data.Aeson.Types.ToJSON Methods toJSON :: NonEmpty a -> Value Source # toEncoding :: NonEmpty a -> Encoding Source # toJSONList :: [NonEmpty a] -> Value Source # toEncodingList :: [NonEmpty a] -> Encoding Source #
ToJSON a => ToJSON (HashSet a) |
Instance details Defined in Data.Aeson.Types.ToJSON Methods toJSON :: HashSet a -> Value Source # toEncoding :: HashSet a -> Encoding Source # toJSONList :: [HashSet a] -> Value Source # toEncodingList :: [HashSet a] -> Encoding Source #
(Vector Vector a, ToJSON a) => ToJSON (Vector a) |
Instance details Defined in Data.Aeson.Types.ToJSON Methods toJSON :: Vector a -> Value Source # toEncoding :: Vector a -> Encoding Source # toJSONList :: [Vector a] -> Value Source # toEncodingList :: [Vector a] -> Encoding Source #
(Storable a, ToJSON a) => ToJSON (Vector a) |
Instance details Defined in Data.Aeson.Types.ToJSON Methods toJSON :: Vector a -> Value Source # toEncoding :: Vector a -> Encoding Source # toJSONList :: [Vector a] -> Value Source # toEncodingList :: [Vector a] -> Encoding Source #
(Prim a, ToJSON a) => ToJSON (Vector a) |
Instance details Defined in Data.Aeson.Types.ToJSON Methods toJSON :: Vector a -> Value Source # toEncoding :: Vector a -> Encoding Source # toJSONList :: [Vector a] -> Value Source # toEncodingList :: [Vector a] -> Encoding Source #
ToJSON a => ToJSON (Vector a) |
Instance details Defined in Data.Aeson.Types.ToJSON Methods toJSON :: Vector a -> Value Source # toEncoding :: Vector a -> Encoding Source # toJSONList :: [Vector a] -> Value Source # toEncodingList :: [Vector a] -> Encoding Source #
ToJSON a => ToJSON (Array a) |
Instance details Defined in Data.Aeson.Types.ToJSON Methods toJSON :: Array a -> Value Source # toEncoding :: Array a -> Encoding Source # toJSONList :: [Array a] -> Value Source # toEncodingList :: [Array a] -> Encoding Source #
ToJSON a => ToJSON (DList a) |
Instance details Defined in Data.Aeson.Types.ToJSON Methods toJSON :: DList a -> Value Source # toEncoding :: DList a -> Encoding Source # toJSONList :: [DList a] -> Value Source # toEncodingList :: [DList a] -> Encoding Source #
ToJSON a => ToJSON (IntMap a) |
Instance details Defined in Data.Aeson.Types.ToJSON Methods toJSON :: IntMap a -> Value Source # toEncoding :: IntMap a -> Encoding Source # toJSONList :: [IntMap a] -> Value Source # toEncodingList :: [IntMap a] -> Encoding Source #
ToJSON a => ToJSON (Seq a) |
Instance details Defined in Data.Aeson.Types.ToJSON Methods toJSON :: Seq a -> Value Source # toEncoding :: Seq a -> Encoding Source # toJSONList :: [Seq a] -> Value Source # toEncodingList :: [Seq a] -> Encoding Source #
ToJSON v => ToJSON (Tree v) |
Instance details Defined in Data.Aeson.Types.ToJSON Methods toJSON :: Tree v -> Value Source # toEncoding :: Tree v -> Encoding Source # toJSONList :: [Tree v] -> Value Source # toEncodingList :: [Tree v] -> Encoding Source #
HasResolution a => ToJSON (Fixed a) |
Instance details Defined in Data.Aeson.Types.ToJSON Methods toJSON :: Fixed a -> Value Source # toEncoding :: Fixed a -> Encoding Source # toJSONList :: [Fixed a] -> Value Source # toEncodingList :: [Fixed a] -> Encoding Source #
(Prim a, ToJSON a) => ToJSON (PrimArray a) |
Instance details Defined in Data.Aeson.Types.ToJSON Methods toJSON :: PrimArray a -> Value Source # toEncoding :: PrimArray a -> Encoding Source # toJSONList :: [PrimArray a] -> Value Source # toEncodingList :: [PrimArray a] -> Encoding Source #
ToJSON a => ToJSON (Set a) |
Instance details Defined in Data.Aeson.Types.ToJSON Methods toJSON :: Set a -> Value Source # toEncoding :: Set a -> Encoding Source # toJSONList :: [Set a] -> Value Source # toEncodingList :: [Set a] -> Encoding Source #
ToJSON a => ToJSON (SmallArray a) |
Instance details Defined in Data.Aeson.Types.ToJSON Methods toJSON :: SmallArray a -> Value Source # toEncoding :: SmallArray a -> Encoding Source # toJSONList :: [SmallArray a] -> Value Source # toEncodingList :: [SmallArray a] -> Encoding Source #
(ToJSON a, ToJSON b) => ToJSON (Either a b) |
Instance details Defined in Data.Aeson.Types.ToJSON Methods toJSON :: Either a b -> Value Source # toEncoding :: Either a b -> Encoding Source # toJSONList :: [Either a b] -> Value Source # toEncodingList :: [Either a b] -> Encoding Source #
(ToJSON a, ToJSON b) => ToJSON (a, b) |
Instance details Defined in Data.Aeson.Types.ToJSON Methods toJSON :: (a, b) -> Value Source # toEncoding :: (a, b) -> Encoding Source # toJSONList :: [(a, b)] -> Value Source # toEncodingList :: [(a, b)] -> Encoding Source #
(ToJSON v, ToJSONKey k) => ToJSON (HashMap k v) |
Instance details Defined in Data.Aeson.Types.ToJSON Methods toJSON :: HashMap k v -> Value Source # toEncoding :: HashMap k v -> Encoding Source # toJSONList :: [HashMap k v] -> Value Source # toEncodingList :: [HashMap k v] -> Encoding Source #
(ToJSON v, ToJSONKey k) => ToJSON (Map k v) |
Instance details Defined in Data.Aeson.Types.ToJSON Methods toJSON :: Map k v -> Value Source # toEncoding :: Map k v -> Encoding Source # toJSONList :: [Map k v] -> Value Source # toEncodingList :: [Map k v] -> Encoding Source #
ToJSON (Proxy a) |
Instance details Defined in Data.Aeson.Types.ToJSON Methods toJSON :: Proxy a -> Value Source # toEncoding :: Proxy a -> Encoding Source # toJSONList :: [Proxy a] -> Value Source # toEncodingList :: [Proxy a] -> Encoding Source #
(ToJSON a, ToJSON b, ToJSON c) => ToJSON (a, b, c) |
Instance details Defined in Data.Aeson.Types.ToJSON Methods toJSON :: (a, b, c) -> Value Source # toEncoding :: (a, b, c) -> Encoding Source # toJSONList :: [(a, b, c)] -> Value Source # toEncodingList :: [(a, b, c)] -> Encoding Source #
ToJSON a => ToJSON (Const a b) |
Instance details Defined in Data.Aeson.Types.ToJSON Methods toJSON :: Const a b -> Value Source # toEncoding :: Const a b -> Encoding Source # toJSONList :: [Const a b] -> Value Source # toEncodingList :: [Const a b] -> Encoding Source #
ToJSON b => ToJSON (Tagged a b) |
Instance details Defined in Data.Aeson.Types.ToJSON Methods toJSON :: Tagged a b -> Value Source # toEncoding :: Tagged a b -> Encoding Source # toJSONList :: [Tagged a b] -> Value Source # toEncodingList :: [Tagged a b] -> Encoding Source #
(ToJSON a, ToJSON b, ToJSON c, ToJSON d) => ToJSON (a, b, c, d) |
Instance details Defined in Data.Aeson.Types.ToJSON Methods toJSON :: (a, b, c, d) -> Value Source # toEncoding :: (a, b, c, d) -> Encoding Source # toJSONList :: [(a, b, c, d)] -> Value Source # toEncodingList :: [(a, b, c, d)] -> Encoding Source #
(ToJSON1 f, ToJSON1 g, ToJSON a) => ToJSON (Sum f g a) |
Instance details Defined in Data.Aeson.Types.ToJSON Methods toJSON :: Sum f g a -> Value Source # toEncoding :: Sum f g a -> Encoding Source # toJSONList :: [Sum f g a] -> Value Source # toEncodingList :: [Sum f g a] -> Encoding Source #
(ToJSON1 f, ToJSON1 g, ToJSON a) => ToJSON (Product f g a) |
Instance details Defined in Data.Aeson.Types.ToJSON Methods toJSON :: Product f g a -> Value Source # toEncoding :: Product f g a -> Encoding Source # toJSONList :: [Product f g a] -> Value Source # toEncodingList :: [Product f g a] -> Encoding Source #
(ToJSON a, ToJSON b, ToJSON c, ToJSON d, ToJSON e) => ToJSON (a, b, c, d, e) |
Instance details Defined in Data.Aeson.Types.ToJSON Methods toJSON :: (a, b, c, d, e) -> Value Source # toEncoding :: (a, b, c, d, e) -> Encoding Source # toJSONList :: [(a, b, c, d, e)] -> Value Source # toEncodingList :: [(a, b, c, d, e)] -> Encoding Source #
(ToJSON1 f, ToJSON1 g, ToJSON a) => ToJSON (Compose f g a) |
Instance details Defined in Data.Aeson.Types.ToJSON Methods toJSON :: Compose f g a -> Value Source # toEncoding :: Compose f g a -> Encoding Source # toJSONList :: [Compose f g a] -> Value Source # toEncodingList :: [Compose f g a] -> Encoding Source #
(ToJSON a, ToJSON b, ToJSON c, ToJSON d, ToJSON e, ToJSON f) => ToJSON (a, b, c, d, e, f) |
Instance details Defined in Data.Aeson.Types.ToJSON Methods toJSON :: (a, b, c, d, e, f) -> Value Source # toEncoding :: (a, b, c, d, e, f) -> Encoding Source # toJSONList :: [(a, b, c, d, e, f)] -> Value Source # toEncodingList :: [(a, b, c, d, e, f)] -> Encoding Source #
(ToJSON a, ToJSON b, ToJSON c, ToJSON d, ToJSON e, ToJSON f, ToJSON g) => ToJSON (a, b, c, d, e, f, g) |
Instance details Defined in Data.Aeson.Types.ToJSON Methods toJSON :: (a, b, c, d, e, f, g) -> Value Source # toEncoding :: (a, b, c, d, e, f, g) -> Encoding Source # toJSONList :: [(a, b, c, d, e, f, g)] -> Value Source # toEncodingList :: [(a, b, c, d, e, f, g)] -> Encoding Source #
(ToJSON a, ToJSON b, ToJSON c, ToJSON d, ToJSON e, ToJSON f, ToJSON g, ToJSON h) => ToJSON (a, b, c, d, e, f, g, h) |
Instance details Defined in Data.Aeson.Types.ToJSON Methods toJSON :: (a, b, c, d, e, f, g, h) -> Value Source # toEncoding :: (a, b, c, d, e, f, g, h) -> Encoding Source # toJSONList :: [(a, b, c, d, e, f, g, h)] -> Value Source # toEncodingList :: [(a, b, c, d, e, f, g, h)] -> Encoding Source #
(ToJSON a, ToJSON b, ToJSON c, ToJSON d, ToJSON e, ToJSON f, ToJSON g, ToJSON h, ToJSON i) => ToJSON (a, b, c, d, e, f, g, h, i) |
Instance details Defined in Data.Aeson.Types.ToJSON Methods toJSON :: (a, b, c, d, e, f, g, h, i) -> Value Source # toEncoding :: (a, b, c, d, e, f, g, h, i) -> Encoding Source # toJSONList :: [(a, b, c, d, e, f, g, h, i)] -> Value Source # toEncodingList :: [(a, b, c, d, e, f, g, h, i)] -> Encoding Source #
(ToJSON a, ToJSON b, ToJSON c, ToJSON d, ToJSON e, ToJSON f, ToJSON g, ToJSON h, ToJSON i, ToJSON j) => ToJSON (a, b, c, d, e, f, g, h, i, j) |
Instance details Defined in Data.Aeson.Types.ToJSON Methods toJSON :: (a, b, c, d, e, f, g, h, i, j) -> Value Source # toEncoding :: (a, b, c, d, e, f, g, h, i, j) -> Encoding Source # toJSONList :: [(a, b, c, d, e, f, g, h, i, j)] -> Value Source # toEncodingList :: [(a, b, c, d, e, f, g, h, i, j)] -> Encoding Source #
(ToJSON a, ToJSON b, ToJSON c, ToJSON d, ToJSON e, ToJSON f, ToJSON g, ToJSON h, ToJSON i, ToJSON j, ToJSON k) => ToJSON (a, b, c, d, e, f, g, h, i, j, k) |
Instance details Defined in Data.Aeson.Types.ToJSON Methods toJSON :: (a, b, c, d, e, f, g, h, i, j, k) -> Value Source # toEncoding :: (a, b, c, d, e, f, g, h, i, j, k) -> Encoding Source # toJSONList :: [(a, b, c, d, e, f, g, h, i, j, k)] -> Value Source # toEncodingList :: [(a, b, c, d, e, f, g, h, i, j, k)] -> Encoding Source #
(ToJSON a, ToJSON b, ToJSON c, ToJSON d, ToJSON e, ToJSON f, ToJSON g, ToJSON h, ToJSON i, ToJSON j, ToJSON k, ToJSON l) => ToJSON (a, b, c, d, e, f, g, h, i, j, k, l) |
Instance details Defined in Data.Aeson.Types.ToJSON Methods toJSON :: (a, b, c, d, e, f, g, h, i, j, k, l) -> Value Source # toEncoding :: (a, b, c, d, e, f, g, h, i, j, k, l) -> Encoding Source # toJSONList :: [(a, b, c, d, e, f, g, h, i, j, k, l)] -> Value Source # toEncodingList :: [(a, b, c, d, e, f, g, h, i, j, k, l)] -> Encoding Source #
(ToJSON a, ToJSON b, ToJSON c, ToJSON d, ToJSON e, ToJSON f, ToJSON g, ToJSON h, ToJSON i, ToJSON j, ToJSON k, ToJSON l, ToJSON m) => ToJSON (a, b, c, d, e, f, g, h, i, j, k, l, m) |
Instance details Defined in Data.Aeson.Types.ToJSON Methods toJSON :: (a, b, c, d, e, f, g, h, i, j, k, l, m) -> Value Source # toEncoding :: (a, b, c, d, e, f, g, h, i, j, k, l, m) -> Encoding Source # toJSONList :: [(a, b, c, d, e, f, g, h, i, j, k, l, m)] -> Value Source # toEncodingList :: [(a, b, c, d, e, f, g, h, i, j, k, l, m)] -> Encoding Source #
(ToJSON a, ToJSON b, ToJSON c, ToJSON d, ToJSON e, ToJSON f, ToJSON g, ToJSON h, ToJSON i, ToJSON j, ToJSON k, ToJSON l, ToJSON m, ToJSON n) => ToJSON (a, b, c, d, e, f, g, h, i, j, k, l, m, n) |
Instance details Defined in Data.Aeson.Types.ToJSON Methods toJSON :: (a, b, c, d, e, f, g, h, i, j, k, l, m, n) -> Value Source # toEncoding :: (a, b, c, d, e, f, g, h, i, j, k, l, m, n) -> Encoding Source # toJSONList :: [(a, b, c, d, e, f, g, h, i, j, k, l, m, n)] -> Value Source # toEncodingList :: [(a, b, c, d, e, f, g, h, i, j, k, l, m, n)] -> Encoding Source #
(ToJSON a, ToJSON b, ToJSON c, ToJSON d, ToJSON e, ToJSON f, ToJSON g, ToJSON h, ToJSON i, ToJSON j, ToJSON k, ToJSON l, ToJSON m, ToJSON n, ToJSON o) => ToJSON (a, b, c, d, e, f, g, h, i, j, k, l, m, n, o) |
Instance details Defined in Data.Aeson.Types.ToJSON Methods toJSON :: (a, b, c, d, e, f, g, h, i, j, k, l, m, n, o) -> Value Source # toEncoding :: (a, b, c, d, e, f, g, h, i, j, k, l, m, n, o) -> Encoding Source # toJSONList :: [(a, b, c, d, e, f, g, h, i, j, k, l, m, n, o)] -> Value Source # toEncodingList :: [(a, b, c, d, e, f, g, h, i, j, k, l, m, n, o)] -> Encoding Source #

class KeyValue kv where Source #

A key-value pair for encoding a JSON object.

Methods

(.=) :: ToJSON v => Text -> v -> kv infixr 8 Source #

#### Instances

Instances details

KeyValue Series |
Instance details Defined in Data.Aeson.Types.ToJSON Methods (.=) :: ToJSON v => Text -> v -> Series Source #
KeyValue Object | Constructs a singleton `HashMap`. For calling functions that demand an `Object` for constructing objects. To be used in conjunction with `mconcat`. Prefer to use `object` where possible.
Instance details Defined in Data.Aeson.Types.ToJSON Methods (.=) :: ToJSON v => Text -> v -> Object Source #
KeyValue Pair |
Instance details Defined in Data.Aeson.Types.ToJSON Methods (.=) :: ToJSON v => Text -> v -> Pair Source #

## Generic JSON classes and options

class GFromJSON arity (f :: Type -> Type) Source #

Class of generic representation types that can be converted from JSON.

Minimal complete definition

gParseJSON

#### Instances

Instances details

GFromJSON One Par1 |
Instance details Defined in Data.Aeson.Types.FromJSON Methods gParseJSON :: Options -> FromArgs One a -> Value -> Parser (Par1 a) Source #
GFromJSON arity (V1 :: Type -> Type) |
Instance details Defined in Data.Aeson.Types.FromJSON Methods gParseJSON :: Options -> FromArgs arity a -> Value -> Parser (V1 a) Source #
FromJSON1 f => GFromJSON One (Rec1 f) |
Instance details Defined in Data.Aeson.Types.FromJSON Methods gParseJSON :: Options -> FromArgs One a -> Value -> Parser (Rec1 f a) Source #
(GFromJSON' arity a, Datatype d) => GFromJSON arity (D1 d a) |
Instance details Defined in Data.Aeson.Types.FromJSON Methods gParseJSON :: Options -> FromArgs arity a0 -> Value -> Parser (D1 d a a0) Source #
FromJSON a => GFromJSON arity (K1 i a :: Type -> Type) |
Instance details Defined in Data.Aeson.Types.FromJSON Methods gParseJSON :: Options -> FromArgs arity a0 -> Value -> Parser (K1 i a a0) Source #
GFromJSON arity a => GFromJSON arity (M1 i c a) |
Instance details Defined in Data.Aeson.Types.FromJSON Methods gParseJSON :: Options -> FromArgs arity a0 -> Value -> Parser (M1 i c a a0) Source #
(FromJSON1 f, GFromJSON One g) => GFromJSON One (f :.: g) |
Instance details Defined in Data.Aeson.Types.FromJSON Methods gParseJSON :: Options -> FromArgs One a -> Value -> Parser ((f :.: g) a) Source #

type GToJSON = GToJSON Value Source #

type GToEncoding = GToJSON Encoding Source #

genericToJSON :: (Generic a, GToJSON Value Zero (Rep a)) => Options -> a -> Value Source #

A configurable generic JSON creator. This function applied to `defaultOptions` is used as the default for `toJSON` when the type is an instance of `Generic`.

genericToEncoding :: (Generic a, GToJSON Encoding Zero (Rep a)) => Options -> a -> Encoding Source #

A configurable generic JSON encoder. This function applied to `defaultOptions` is used as the default for `toEncoding` when the type is an instance of `Generic`.

genericParseJSON :: (Generic a, GFromJSON Zero (Rep a)) => Options -> Value -> Parser a Source #

A configurable generic JSON decoder. This function applied to `defaultOptions` is used as the default for `parseJSON` when the type is an instance of `Generic`.

defaultOptions :: Options Source #

Default encoding `Options`:

    Options
    { fieldLabelModifier      = id
    , constructorTagModifier  = id
    , allNullaryToStringTag   = True
    , omitNothingFields       = False
    , sumEncoding             = defaultTaggedObject
    , unwrapUnaryRecords      = False
    , tagSingleConstructors   = False
    , rejectUnknownFields     = False
    }

# Inspecting ``Value`s`

withObject :: String -> (Object -> Parser a) -> Value -> Parser a Source #

``withObject` name f value` applies `f` to the `Object` when `value` is an `Object` and fails otherwise.

#### Error message example

    withObject "MyType" f (String "oops")
    -- Error: "parsing MyType failed, expected Object, but encountered String"

withText :: String -> (Text -> Parser a) -> Value -> Parser a Source #

``withText` name f value` applies `f` to the `Text` when `value` is a `String` and fails otherwise.

#### Error message example

    withText "MyType" f Null
    -- Error: "parsing MyType failed, expected String, but encountered Null"

withArray :: String -> (Array -> Parser a) -> Value -> Parser a Source #

``withArray` expected f value` applies `f` to the `Array` when `value` is an `Array` and fails otherwise.

#### Error message example

    withArray "MyType" f (String "oops")
    -- Error: "parsing MyType failed, expected Array, but encountered String"

withNumber :: String -> (Number -> Parser a) -> Value -> Parser a Source #

Deprecated: Use withScientific instead

``withNumber` expected f value` applies `f` to the `Number` when `value` is a `Number` and fails using ``typeMismatch` expected` otherwise.

withScientific :: String -> (Scientific -> Parser a) -> Value -> Parser a Source #

``withScientific` name f value` applies `f` to the `Scientific` number when `value` is a `Number` and fails using `typeMismatch` otherwise.

Warning: If you are converting from a scientific to an unbounded type such as `Integer` you may want to add a restriction on the size of the exponent (see `withBoundedScientific`) to prevent malicious input from filling up the memory of the target system.

#### Error message example

    withScientific "MyType" f (String "oops")
    -- Error: "parsing MyType failed, expected Number, but encountered String"

withBool :: String -> (Bool -> Parser a) -> Value -> Parser a Source #

``withBool` expected f value` applies `f` to the `Bool` when `value` is a `Boolean` and fails otherwise.

#### Error message example

    withBool "MyType" f (String "oops")
    -- Error: "parsing MyType failed, expected Boolean, but encountered String"

withEmbeddedJSON :: String -> (Value -> Parser a) -> Value -> Parser a Source #

Decode a nested JSON-encoded string.

# Constructors and accessors

data Series Source #

A series of values that, when encoded, should be separated by commas. Since 0.11.0.0, the `.=` operator is overloaded to create either `(Text, Value)` or `Series`. You can use Series when encoding directly to a bytestring builder as in the following example:

    toEncoding (Person name age) = pairs ("name" .= name <> "age" .= age)

#### Instances

Instances details

Semigroup Series |
Instance details Defined in Data.Aeson.Encoding.Internal Methods (<>) :: Series -> Series -> Series # sconcat :: NonEmpty Series -> Series # stimes :: Integral b => b -> Series -> Series #
Monoid Series |
Instance details Defined in Data.Aeson.Encoding.Internal Methods mempty :: Series # mappend :: Series -> Series -> Series # mconcat :: [Series] -> Series #
KeyValue Series |
Instance details Defined in Data.Aeson.Types.ToJSON Methods (.=) :: ToJSON v => Text -> v -> Series Source #
e ~ Encoding => KeyValuePair e Series |
Instance details Defined in Data.Aeson.Types.ToJSON Methods pair :: String -> e -> Series
a ~ Value => FromPairs (Encoding' a) Series |
Instance details Defined in Data.Aeson.Types.ToJSON Methods fromPairs :: Series -> Encoding' a

pairs :: Series -> Encoding Source #

Encode a series of key/value pairs, separated by commas.

foldable :: (Foldable t, ToJSON a) => t a -> Encoding Source #

Encode a `Foldable` as a JSON array.

(.:) :: FromJSON a => Object -> Text -> Parser a Source #

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

This accessor is appropriate if the key and value must be present in an object for it to be valid. If the key and value are optional, use `.:?` instead.

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

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) Source #

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 differs from `.:?` by attempting to parse `Null` the same as any other JSON value, instead of interpreting it as `Nothing`.

(.!=) :: Parser (Maybe a) -> a -> Parser a Source #

Helper for use in combination with `.:?` to provide default values for optional JSON object fields.

This combinator is most useful if the key and value can be absent from an object without affecting its validity and we know a default value to assign in that case. If the key and value are mandatory, use `.:` instead.

Example usage:

     v1 <- o .:? "opt_field_with_dfl" .!= "default_val"
     v2 <- o .:  "mandatory_field"
     v3 <- o .:? "opt_field2"

object :: [Pair] -> Value Source #

Create a `Value` from a list of name/value `Pair`s. If duplicate keys arise, earlier keys and their associated values win.

# Parsing

json :: Parser Value Source #

Parse any JSON value.

The conversion of a parsed value to a Haskell value is deferred until the Haskell value is needed. This may improve performance if only a subset of the results of conversions are needed, but at a cost in thunk allocation.

This function is an alias for `value`. In aeson 0.8 and earlier, it parsed only object or array types, in conformance with the now-obsolete RFC 4627.

#### Warning

If an object contains duplicate keys, only the first one will be kept. For a more flexible alternative, see `jsonWith`.

json' :: Parser Value Source #

Parse any JSON value.

This is a strict version of `json` which avoids building up thunks during parsing; it performs all conversions immediately. Prefer this version if most of the JSON data needs to be accessed.

This function is an alias for `value'`. In aeson 0.8 and earlier, it parsed only object or array types, in conformance with the now-obsolete RFC 4627.

#### Warning

If an object contains duplicate keys, only the first one will be kept. For a more flexible alternative, see `jsonWith'`.

value :: Parser Value Source #

Parse any JSON value. Synonym of `json`.

value' :: Parser Value Source #

Strict version of `value`. Synonym of `json'`.

data Parser a Source #

A JSON parser. N.B. This might not fit your usual understanding of "parser". Instead you might like to think of `Parser` as a "parse result", i.e. a parser to which the input has already been applied.

#### Instances

Instances details

Monad Parser |
Instance details Defined in Data.Aeson.Types.Internal Methods (>>=) :: Parser a -> (a -> Parser b) -> Parser b # (>>) :: Parser a -> Parser b -> Parser b # return :: a -> Parser a #
Functor Parser |
Instance details Defined in Data.Aeson.Types.Internal Methods fmap :: (a -> b) -> Parser a -> Parser b # (<$) :: a -> Parser b -> Parser a #
MonadFail Parser |
Instance details Defined in Data.Aeson.Types.Internal Methods fail :: String -> Parser a #
Applicative Parser |
Instance details Defined in Data.Aeson.Types.Internal Methods pure :: a -> Parser a (<*>) :: Parser (a -> b) -> Parser a -> Parser b liftA2 :: (a -> b -> c) -> Parser a -> Parser b -> Parser c (*>) :: Parser a -> Parser b -> Parser b (<*) :: Parser a -> Parser b -> Parser a
Alternative Parser |
Instance details Defined in Data.Aeson.Types.Internal Methods empty :: Parser a (<|>) :: Parser a -> Parser a -> Parser a some :: Parser a -> Parser [a] many :: Parser a -> Parser [a]
MonadPlus Parser |
Instance details Defined in Data.Aeson.Types.Internal Methods mzero :: Parser a # mplus :: Parser a -> Parser a -> Parser a #
Semigroup (Parser a) |
Instance details Defined in Data.Aeson.Types.Internal Methods (<>) :: Parser a -> Parser a -> Parser a # sconcat :: NonEmpty (Parser a) -> Parser a # stimes :: Integral b => b -> Parser a -> Parser a #
Monoid (Parser a) |
Instance details Defined in Data.Aeson.Types.Internal Methods mempty :: Parser a # mappend :: Parser a -> Parser a -> Parser a # mconcat :: [Parser a] -> Parser a #