Safe Haskell | None |
---|---|
Language | Haskell2010 |
Synopsis
- data LambdaInvocation payload = LambdaInvocation {
- liAwsRequestId :: Text
- liDeadlineMs :: Word64
- liInvokedFunctionArn :: Text
- liTraceId :: Text
- liMobileMetadata :: Maybe MobileInvocationMetadata
- liPayload :: payload
- data LambdaResult payload
- = LambdaSuccess payload
- | LambdaError ErrorInfo
- | LambdaNop
- data LambdaExecutionContext a m b = LambdaExecutionContext {
- lecApiPrefix :: String
- lecHttpManager :: Manager
- lecHandler :: LambdaInvocation a -> m (LambdaResult b)
- data MobileInvocationMetadata = MobileInvocationMetadata {}
- data Text
- class NFData a
- class NFData1 (f :: Type -> Type)
- class Monad m => MonadThrow (m :: Type -> Type)
- throw :: (MonadThrow m, Exception e) => e -> m a
- forever :: Applicative f => f a -> f b
- void :: Functor f => f a -> f ()
- class ToJSON a
- class ToJSON1 (f :: Type -> Type)
- class FromJSON a
- class FromJSON1 (f :: Type -> Type)
- data Options
- (&) :: a -> (a -> b) -> b
- class IsString a where
- fromString :: String -> a
- typeOf :: Typeable a => a -> TypeRep
- data Word64
- module GHC.Generics
Documentation
data LambdaInvocation payload Source #
Represents the data provided to an invocation of the lambda
LambdaInvocation | |
|
Instances
data LambdaResult payload Source #
The two possible results of a Lambda execution: success or failure
LambdaSuccess payload | Denotes success and provides the value to return |
LambdaError ErrorInfo | Denotes failure and provides details |
LambdaNop | Denotes that no invocation was provided |
Instances
data LambdaExecutionContext a m b Source #
LambdaExecutionContext | |
|
data MobileInvocationMetadata Source #
Additional information available only when the Lambda is invoked through the AWS Mobile SDK. This data is currently unstructured, but will be updated to be structured in some future major release.
(Pull requests very welcome.)
MobileInvocationMetadata | |
|
Instances
A space efficient, packed, unboxed Unicode text type.
Instances
Hashable Text | |
Defined in Data.Hashable.Class | |
ToJSON Text | |
Defined in Data.Aeson.Types.ToJSON | |
KeyValue Object | Constructs a singleton |
KeyValue Pair | |
ToJSONKey Text | |
Defined in Data.Aeson.Types.ToJSON | |
FromJSON Text | |
FromJSONKey Text | |
Defined in Data.Aeson.Types.FromJSON | |
Chunk Text | |
Defined in Data.Attoparsec.Internal.Types | |
FoldCase Text | |
Defined in Data.CaseInsensitive.Internal | |
FromPairs Value (DList Pair) | |
Defined in Data.Aeson.Types.ToJSON | |
v ~ Value => KeyValuePair v (DList Pair) | |
Defined in Data.Aeson.Types.ToJSON | |
type State Text | |
Defined in Data.Attoparsec.Internal.Types | |
type ChunkElem Text | |
Defined in Data.Attoparsec.Internal.Types | |
type Item Text | |
A class of types that can be fully evaluated.
Since: deepseq-1.1.0.0
Instances
class NFData1 (f :: Type -> Type) #
A class of functors that can be fully evaluated.
Since: deepseq-1.4.3.0
Instances
NFData1 [] | Since: deepseq-1.4.3.0 |
Defined in Control.DeepSeq | |
NFData1 Maybe | Since: deepseq-1.4.3.0 |
Defined in Control.DeepSeq | |
NFData1 Ratio | Available on Since: deepseq-1.4.3.0 |
Defined in Control.DeepSeq | |
NFData1 Ptr | Since: deepseq-1.4.3.0 |
Defined in Control.DeepSeq | |
NFData1 FunPtr | Since: deepseq-1.4.3.0 |
Defined in Control.DeepSeq | |
NFData1 Min | Since: deepseq-1.4.3.0 |
Defined in Control.DeepSeq | |
NFData1 Max | Since: deepseq-1.4.3.0 |
Defined in Control.DeepSeq | |
NFData1 First | Since: deepseq-1.4.3.0 |
Defined in Control.DeepSeq | |
NFData1 Last | Since: deepseq-1.4.3.0 |
Defined in Control.DeepSeq | |
NFData1 WrappedMonoid | Since: deepseq-1.4.3.0 |
Defined in Control.DeepSeq liftRnf :: (a -> ()) -> WrappedMonoid a -> () # | |
NFData1 Option | Since: deepseq-1.4.3.0 |
Defined in Control.DeepSeq | |
NFData1 StableName | Since: deepseq-1.4.3.0 |
Defined in Control.DeepSeq liftRnf :: (a -> ()) -> StableName a -> () # | |
NFData1 ZipList | Since: deepseq-1.4.3.0 |
Defined in Control.DeepSeq | |
NFData1 Identity | Since: deepseq-1.4.3.0 |
Defined in Control.DeepSeq | |
NFData1 IORef | Since: deepseq-1.4.3.0 |
Defined in Control.DeepSeq | |
NFData1 First | Since: deepseq-1.4.3.0 |
Defined in Control.DeepSeq | |
NFData1 Last | Since: deepseq-1.4.3.0 |
Defined in Control.DeepSeq | |
NFData1 Dual | Since: deepseq-1.4.3.0 |
Defined in Control.DeepSeq | |
NFData1 Sum | Since: deepseq-1.4.3.0 |
Defined in Control.DeepSeq | |
NFData1 Product | Since: deepseq-1.4.3.0 |
Defined in Control.DeepSeq | |
NFData1 Down | Since: deepseq-1.4.3.0 |
Defined in Control.DeepSeq | |
NFData1 MVar | Since: deepseq-1.4.3.0 |
Defined in Control.DeepSeq | |
NFData1 NonEmpty | Since: deepseq-1.4.3.0 |
Defined in Control.DeepSeq | |
NFData1 SmallArray | |
Defined in Data.Primitive.SmallArray liftRnf :: (a -> ()) -> SmallArray a -> () # | |
NFData1 Array | |
Defined in Data.Primitive.Array | |
NFData1 Maybe | |
Defined in Data.Strict.Maybe | |
NFData1 Vector | Since: vector-0.12.1.0 |
Defined in Data.Vector.Unboxed.Base | |
NFData1 Vector | Since: vector-0.12.1.0 |
Defined in Data.Vector.Storable | |
NFData1 Vector | Since: vector-0.12.1.0 |
Defined in Data.Vector.Primitive | |
NFData1 Vector | Since: vector-0.12.1.0 |
Defined in Data.Vector | |
NFData1 LambdaResult Source # | |
Defined in AWS.Lambda.RuntimeAPI.Types liftRnf :: (a -> ()) -> LambdaResult a -> () # | |
NFData1 LambdaInvocation Source # | |
Defined in AWS.Lambda.RuntimeAPI.Types liftRnf :: (a -> ()) -> LambdaInvocation a -> () # | |
NFData a => NFData1 (Either a) | Since: deepseq-1.4.3.0 |
Defined in Control.DeepSeq | |
NFData a => NFData1 ((,) a) | Since: deepseq-1.4.3.0 |
Defined in Control.DeepSeq | |
NFData a => NFData1 (Array a) | Since: deepseq-1.4.3.0 |
Defined in Control.DeepSeq | |
NFData1 (Fixed :: Type -> Type) | Since: deepseq-1.4.3.0 |
Defined in Control.DeepSeq | |
NFData a => NFData1 (Arg a) | Since: deepseq-1.4.3.0 |
Defined in Control.DeepSeq | |
NFData1 (Proxy :: Type -> Type) | Since: deepseq-1.4.3.0 |
Defined in Control.DeepSeq | |
NFData1 (STRef s) | Since: deepseq-1.4.3.0 |
Defined in Control.DeepSeq | |
NFData a => NFData1 (Pair a) | |
Defined in Data.Strict.Tuple | |
NFData a => NFData1 (These a) | |
Defined in Data.Strict.These | |
NFData a => NFData1 (Either a) | |
Defined in Data.Strict.Either | |
NFData a => NFData1 (These a) | Since: these-1.1.1 |
Defined in Data.These | |
NFData1 (MVector s) | Since: vector-0.12.1.0 |
Defined in Data.Vector.Unboxed.Base | |
(NFData a1, NFData a2) => NFData1 ((,,) a1 a2) | Since: deepseq-1.4.3.0 |
Defined in Control.DeepSeq | |
NFData a => NFData1 (Const a :: Type -> Type) | Since: deepseq-1.4.3.0 |
Defined in Control.DeepSeq | |
NFData1 ((:~:) a) | Since: deepseq-1.4.3.0 |
Defined in Control.DeepSeq | |
(NFData1 f, NFData1 g) => NFData1 (These1 f g) | This instance is available only with |
Defined in Data.Functor.These | |
(NFData a1, NFData a2, NFData a3) => NFData1 ((,,,) a1 a2 a3) | Since: deepseq-1.4.3.0 |
Defined in Control.DeepSeq | |
(NFData1 f, NFData1 g) => NFData1 (Product f g) | Since: deepseq-1.4.3.0 |
Defined in Control.DeepSeq | |
(NFData1 f, NFData1 g) => NFData1 (Sum f g) | Since: deepseq-1.4.3.0 |
Defined in Control.DeepSeq | |
NFData1 ((:~~:) a :: Type -> Type) | Since: deepseq-1.4.3.0 |
Defined in Control.DeepSeq | |
(NFData a1, NFData a2, NFData a3, NFData a4) => NFData1 ((,,,,) a1 a2 a3 a4) | Since: deepseq-1.4.3.0 |
Defined in Control.DeepSeq | |
(NFData1 f, NFData1 g) => NFData1 (Compose f g) | Since: deepseq-1.4.3.0 |
Defined in Control.DeepSeq | |
(NFData a1, NFData a2, NFData a3, NFData a4, NFData a5) => NFData1 ((,,,,,) a1 a2 a3 a4 a5) | Since: deepseq-1.4.3.0 |
Defined in Control.DeepSeq | |
(NFData a1, NFData a2, NFData a3, NFData a4, NFData a5, NFData a6) => NFData1 ((,,,,,,) a1 a2 a3 a4 a5 a6) | Since: deepseq-1.4.3.0 |
Defined in Control.DeepSeq | |
(NFData a1, NFData a2, NFData a3, NFData a4, NFData a5, NFData a6, NFData a7) => NFData1 ((,,,,,,,) a1 a2 a3 a4 a5 a6 a7) | Since: deepseq-1.4.3.0 |
Defined in Control.DeepSeq | |
(NFData a1, NFData a2, NFData a3, NFData a4, NFData a5, NFData a6, NFData a7, NFData a8) => NFData1 ((,,,,,,,,) a1 a2 a3 a4 a5 a6 a7 a8) | Since: deepseq-1.4.3.0 |
Defined in Control.DeepSeq |
class Monad m => MonadThrow (m :: Type -> Type) #
A class for monads in which exceptions may be thrown.
Instances should obey the following law:
throwM e >> x = throwM e
In other words, throwing an exception short-circuits the rest of the monadic computation.
Instances
throw :: (MonadThrow m, Exception e) => e -> m a #
Synchronously throw the given exception
Since: safe-exceptions-0.1.0.0
forever :: Applicative f => f a -> f b #
Repeat an action indefinitely.
Using ApplicativeDo
: '
' can be understood as the
pseudo-forever
asdo
expression
do as as ..
with as
repeating.
Examples
A common use of forever
is to process input from network sockets,
Handle
s, and channels
(e.g. MVar
and
Chan
).
For example, here is how we might implement an echo
server, using
forever
both to listen for client connections on a network socket
and to echo client input on client connection handles:
echoServer :: Socket -> IO () echoServer socket =forever
$ do client <- accept socketforkFinally
(echo client) (\_ -> hClose client) where echo :: Handle -> IO () echo client =forever
$ hGetLine client >>= hPutStrLn client
void :: Functor f => f a -> f () #
discards or ignores the result of evaluation, such
as the return value of an void
valueIO
action.
Using ApplicativeDo
: '
' can be understood as the
void
asdo
expression
do as pure ()
with an inferred Functor
constraint.
Examples
Replace the contents of a
with unit:Maybe
Int
>>>
void Nothing
Nothing>>>
void (Just 3)
Just ()
Replace the contents of an
with unit, resulting in an Either
Int
Int
:Either
Int
()
>>>
void (Left 8675309)
Left 8675309>>>
void (Right 8675309)
Right ()
Replace every element of a list with unit:
>>>
void [1,2,3]
[(),(),()]
Replace the second element of a pair with unit:
>>>
void (1,2)
(1,())
Discard the result of an IO
action:
>>>
mapM print [1,2]
1 2 [(),()]>>>
void $ mapM print [1,2]
1 2
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 writeText
literals. {-# LANGUAGE OverloadedStrings #-} data Coord = Coord { x :: Double, y :: Double } instanceToJSON
Coord wheretoJSON
(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
clause to your
datatype and declare a Generic
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 } derivingGeneric
instanceToJSON
Coord wheretoEncoding
=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
} instanceToJSON
Coord wheretoJSON
=genericToJSON
customOptionstoEncoding
=genericToEncoding
customOptions
Previous versions of this library only had the toJSON
method. Adding
toEncoding
had two reasons:
- toEncoding is more efficient for the common case that the output of
toJSON
is directly serialized to aByteString
. Further, expressing either method in terms of the other would be non-optimal. - 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 oftoEncoding
usetoJSON
. This produces correct results, but since it performs an intermediate conversion to aValue
, it will be less efficient than directly emitting anEncoding
. (this also means that specifying nothing more thaninstance ToJSON Coord
would be sufficient as a generically decoding instance, but there probably exists no good reason to not specifytoEncoding
in new instances.)
Instances
class ToJSON1 (f :: Type -> Type) #
Lifting of the ToJSON
class to unary type constructors.
Instead of manually writing your ToJSON1
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
toJSON1
.
To use the second, simply add a deriving
clause to your
datatype and declare a Generic1
ToJSON1
instance for your datatype without giving
definitions for liftToJSON
or liftToEncoding
.
For example:
{-# LANGUAGE DeriveGeneric #-} import GHC.Generics data Pair = Pair { pairFst :: a, pairSnd :: b } derivingGeneric1
instanceToJSON
a =>ToJSON1
(Pair a)
If the default implementation doesn't give exactly the results you want,
you can customize the generic encoding with only a tiny amount of
effort, using genericLiftToJSON
and genericLiftToEncoding
with
your preferred Options
:
customOptions =defaultOptions
{fieldLabelModifier
=map
toUpper
} instanceToJSON
a =>ToJSON1
(Pair a) whereliftToJSON
=genericLiftToJSON
customOptionsliftToEncoding
=genericLiftToEncoding
customOptions
See also ToJSON
.
Instances
ToJSON1 [] | |
Defined in Data.Aeson.Types.ToJSON liftToJSON :: (a -> Value) -> ([a] -> Value) -> [a] -> Value # liftToJSONList :: (a -> Value) -> ([a] -> Value) -> [[a]] -> Value # liftToEncoding :: (a -> Encoding) -> ([a] -> Encoding) -> [a] -> Encoding # liftToEncodingList :: (a -> Encoding) -> ([a] -> Encoding) -> [[a]] -> Encoding # | |
ToJSON1 Maybe | |
Defined in Data.Aeson.Types.ToJSON liftToJSON :: (a -> Value) -> ([a] -> Value) -> Maybe a -> Value # liftToJSONList :: (a -> Value) -> ([a] -> Value) -> [Maybe a] -> Value # liftToEncoding :: (a -> Encoding) -> ([a] -> Encoding) -> Maybe a -> Encoding # liftToEncodingList :: (a -> Encoding) -> ([a] -> Encoding) -> [Maybe a] -> Encoding # | |
ToJSON1 Min | |
Defined in Data.Aeson.Types.ToJSON | |
ToJSON1 Max | |
Defined in Data.Aeson.Types.ToJSON | |
ToJSON1 First | |
Defined in Data.Aeson.Types.ToJSON liftToJSON :: (a -> Value) -> ([a] -> Value) -> First a -> Value # liftToJSONList :: (a -> Value) -> ([a] -> Value) -> [First a] -> Value # liftToEncoding :: (a -> Encoding) -> ([a] -> Encoding) -> First a -> Encoding # liftToEncodingList :: (a -> Encoding) -> ([a] -> Encoding) -> [First a] -> Encoding # | |
ToJSON1 Last | |
Defined in Data.Aeson.Types.ToJSON | |
ToJSON1 WrappedMonoid | |
Defined in Data.Aeson.Types.ToJSON liftToJSON :: (a -> Value) -> ([a] -> Value) -> WrappedMonoid a -> Value # liftToJSONList :: (a -> Value) -> ([a] -> Value) -> [WrappedMonoid a] -> Value # liftToEncoding :: (a -> Encoding) -> ([a] -> Encoding) -> WrappedMonoid a -> Encoding # liftToEncodingList :: (a -> Encoding) -> ([a] -> Encoding) -> [WrappedMonoid a] -> Encoding # | |
ToJSON1 Option | |
Defined in Data.Aeson.Types.ToJSON liftToJSON :: (a -> Value) -> ([a] -> Value) -> Option a -> Value # liftToJSONList :: (a -> Value) -> ([a] -> Value) -> [Option a] -> Value # liftToEncoding :: (a -> Encoding) -> ([a] -> Encoding) -> Option a -> Encoding # liftToEncodingList :: (a -> Encoding) -> ([a] -> Encoding) -> [Option a] -> Encoding # | |
ToJSON1 Identity | |
Defined in Data.Aeson.Types.ToJSON liftToJSON :: (a -> Value) -> ([a] -> Value) -> Identity a -> Value # liftToJSONList :: (a -> Value) -> ([a] -> Value) -> [Identity a] -> Value # liftToEncoding :: (a -> Encoding) -> ([a] -> Encoding) -> Identity a -> Encoding # liftToEncodingList :: (a -> Encoding) -> ([a] -> Encoding) -> [Identity a] -> Encoding # | |
ToJSON1 First | |
Defined in Data.Aeson.Types.ToJSON liftToJSON :: (a -> Value) -> ([a] -> Value) -> First a -> Value # liftToJSONList :: (a -> Value) -> ([a] -> Value) -> [First a] -> Value # liftToEncoding :: (a -> Encoding) -> ([a] -> Encoding) -> First a -> Encoding # liftToEncodingList :: (a -> Encoding) -> ([a] -> Encoding) -> [First a] -> Encoding # | |
ToJSON1 Last | |
Defined in Data.Aeson.Types.ToJSON | |
ToJSON1 Dual | |
Defined in Data.Aeson.Types.ToJSON | |
ToJSON1 NonEmpty | |
Defined in Data.Aeson.Types.ToJSON liftToJSON :: (a -> Value) -> ([a] -> Value) -> NonEmpty a -> Value # liftToJSONList :: (a -> Value) -> ([a] -> Value) -> [NonEmpty a] -> Value # liftToEncoding :: (a -> Encoding) -> ([a] -> Encoding) -> NonEmpty a -> Encoding # liftToEncodingList :: (a -> Encoding) -> ([a] -> Encoding) -> [NonEmpty a] -> Encoding # | |
ToJSON1 IntMap | |
Defined in Data.Aeson.Types.ToJSON liftToJSON :: (a -> Value) -> ([a] -> Value) -> IntMap a -> Value # liftToJSONList :: (a -> Value) -> ([a] -> Value) -> [IntMap a] -> Value # liftToEncoding :: (a -> Encoding) -> ([a] -> Encoding) -> IntMap a -> Encoding # liftToEncodingList :: (a -> Encoding) -> ([a] -> Encoding) -> [IntMap a] -> Encoding # | |
ToJSON1 Tree | |
Defined in Data.Aeson.Types.ToJSON | |
ToJSON1 Seq | |
Defined in Data.Aeson.Types.ToJSON | |
ToJSON1 Set | |
Defined in Data.Aeson.Types.ToJSON | |
ToJSON1 DNonEmpty | Since: aeson-1.5.3.0 |
Defined in Data.Aeson.Types.ToJSON liftToJSON :: (a -> Value) -> ([a] -> Value) -> DNonEmpty a -> Value # liftToJSONList :: (a -> Value) -> ([a] -> Value) -> [DNonEmpty a] -> Value # liftToEncoding :: (a -> Encoding) -> ([a] -> Encoding) -> DNonEmpty a -> Encoding # liftToEncodingList :: (a -> Encoding) -> ([a] -> Encoding) -> [DNonEmpty a] -> Encoding # | |
ToJSON1 DList | |
Defined in Data.Aeson.Types.ToJSON liftToJSON :: (a -> Value) -> ([a] -> Value) -> DList a -> Value # liftToJSONList :: (a -> Value) -> ([a] -> Value) -> [DList a] -> Value # liftToEncoding :: (a -> Encoding) -> ([a] -> Encoding) -> DList a -> Encoding # liftToEncodingList :: (a -> Encoding) -> ([a] -> Encoding) -> [DList a] -> Encoding # | |
ToJSON1 Maybe | Since: aeson-1.5.3.0 |
Defined in Data.Aeson.Types.ToJSON liftToJSON :: (a -> Value) -> ([a] -> Value) -> Maybe a -> Value # liftToJSONList :: (a -> Value) -> ([a] -> Value) -> [Maybe a] -> Value # liftToEncoding :: (a -> Encoding) -> ([a] -> Encoding) -> Maybe a -> Encoding # liftToEncodingList :: (a -> Encoding) -> ([a] -> Encoding) -> [Maybe a] -> Encoding # | |
ToJSON1 HashSet | |
Defined in Data.Aeson.Types.ToJSON liftToJSON :: (a -> Value) -> ([a] -> Value) -> HashSet a -> Value # liftToJSONList :: (a -> Value) -> ([a] -> Value) -> [HashSet a] -> Value # liftToEncoding :: (a -> Encoding) -> ([a] -> Encoding) -> HashSet a -> Encoding # liftToEncodingList :: (a -> Encoding) -> ([a] -> Encoding) -> [HashSet a] -> Encoding # | |
ToJSON1 Vector | |
Defined in Data.Aeson.Types.ToJSON liftToJSON :: (a -> Value) -> ([a] -> Value) -> Vector a -> Value # liftToJSONList :: (a -> Value) -> ([a] -> Value) -> [Vector a] -> Value # liftToEncoding :: (a -> Encoding) -> ([a] -> Encoding) -> Vector a -> Encoding # liftToEncodingList :: (a -> Encoding) -> ([a] -> Encoding) -> [Vector a] -> Encoding # | |
ToJSON1 LambdaResult Source # | |
Defined in AWS.Lambda.RuntimeAPI.Types liftToJSON :: (a -> Value) -> ([a] -> Value) -> LambdaResult a -> Value # liftToJSONList :: (a -> Value) -> ([a] -> Value) -> [LambdaResult a] -> Value # liftToEncoding :: (a -> Encoding) -> ([a] -> Encoding) -> LambdaResult a -> Encoding # liftToEncodingList :: (a -> Encoding) -> ([a] -> Encoding) -> [LambdaResult a] -> Encoding # | |
ToJSON1 LambdaInvocation Source # | |
Defined in AWS.Lambda.RuntimeAPI.Types liftToJSON :: (a -> Value) -> ([a] -> Value) -> LambdaInvocation a -> Value # liftToJSONList :: (a -> Value) -> ([a] -> Value) -> [LambdaInvocation a] -> Value # liftToEncoding :: (a -> Encoding) -> ([a] -> Encoding) -> LambdaInvocation a -> Encoding # liftToEncodingList :: (a -> Encoding) -> ([a] -> Encoding) -> [LambdaInvocation a] -> Encoding # | |
ToJSON a => ToJSON1 (Either a) | |
Defined in Data.Aeson.Types.ToJSON liftToJSON :: (a0 -> Value) -> ([a0] -> Value) -> Either a a0 -> Value # liftToJSONList :: (a0 -> Value) -> ([a0] -> Value) -> [Either a a0] -> Value # liftToEncoding :: (a0 -> Encoding) -> ([a0] -> Encoding) -> Either a a0 -> Encoding # liftToEncodingList :: (a0 -> Encoding) -> ([a0] -> Encoding) -> [Either a a0] -> Encoding # | |
ToJSON a => ToJSON1 ((,) a) | |
Defined in Data.Aeson.Types.ToJSON liftToJSON :: (a0 -> Value) -> ([a0] -> Value) -> (a, a0) -> Value # liftToJSONList :: (a0 -> Value) -> ([a0] -> Value) -> [(a, a0)] -> Value # liftToEncoding :: (a0 -> Encoding) -> ([a0] -> Encoding) -> (a, a0) -> Encoding # liftToEncodingList :: (a0 -> Encoding) -> ([a0] -> Encoding) -> [(a, a0)] -> Encoding # | |
ToJSONKey k => ToJSON1 (HashMap k) | |
Defined in Data.Aeson.Types.ToJSON liftToJSON :: (a -> Value) -> ([a] -> Value) -> HashMap k a -> Value # liftToJSONList :: (a -> Value) -> ([a] -> Value) -> [HashMap k a] -> Value # liftToEncoding :: (a -> Encoding) -> ([a] -> Encoding) -> HashMap k a -> Encoding # liftToEncodingList :: (a -> Encoding) -> ([a] -> Encoding) -> [HashMap k a] -> Encoding # | |
ToJSONKey k => ToJSON1 (Map k) | |
Defined in Data.Aeson.Types.ToJSON liftToJSON :: (a -> Value) -> ([a] -> Value) -> Map k a -> Value # liftToJSONList :: (a -> Value) -> ([a] -> Value) -> [Map k a] -> Value # liftToEncoding :: (a -> Encoding) -> ([a] -> Encoding) -> Map k a -> Encoding # liftToEncodingList :: (a -> Encoding) -> ([a] -> Encoding) -> [Map k a] -> Encoding # | |
ToJSON1 (Proxy :: Type -> Type) | |
Defined in Data.Aeson.Types.ToJSON liftToJSON :: (a -> Value) -> ([a] -> Value) -> Proxy a -> Value # liftToJSONList :: (a -> Value) -> ([a] -> Value) -> [Proxy a] -> Value # liftToEncoding :: (a -> Encoding) -> ([a] -> Encoding) -> Proxy a -> Encoding # liftToEncodingList :: (a -> Encoding) -> ([a] -> Encoding) -> [Proxy a] -> Encoding # | |
ToJSON a => ToJSON1 (Pair a) | Since: aeson-1.5.3.0 |
Defined in Data.Aeson.Types.ToJSON liftToJSON :: (a0 -> Value) -> ([a0] -> Value) -> Pair a a0 -> Value # liftToJSONList :: (a0 -> Value) -> ([a0] -> Value) -> [Pair a a0] -> Value # liftToEncoding :: (a0 -> Encoding) -> ([a0] -> Encoding) -> Pair a a0 -> Encoding # liftToEncodingList :: (a0 -> Encoding) -> ([a0] -> Encoding) -> [Pair a a0] -> Encoding # | |
ToJSON a => ToJSON1 (These a) | Since: aeson-1.5.3.0 |
Defined in Data.Aeson.Types.ToJSON liftToJSON :: (a0 -> Value) -> ([a0] -> Value) -> These a a0 -> Value # liftToJSONList :: (a0 -> Value) -> ([a0] -> Value) -> [These a a0] -> Value # liftToEncoding :: (a0 -> Encoding) -> ([a0] -> Encoding) -> These a a0 -> Encoding # liftToEncodingList :: (a0 -> Encoding) -> ([a0] -> Encoding) -> [These a a0] -> Encoding # | |
ToJSON a => ToJSON1 (Either a) | Since: aeson-1.5.3.0 |
Defined in Data.Aeson.Types.ToJSON liftToJSON :: (a0 -> Value) -> ([a0] -> Value) -> Either a a0 -> Value # liftToJSONList :: (a0 -> Value) -> ([a0] -> Value) -> [Either a a0] -> Value # liftToEncoding :: (a0 -> Encoding) -> ([a0] -> Encoding) -> Either a a0 -> Encoding # liftToEncodingList :: (a0 -> Encoding) -> ([a0] -> Encoding) -> [Either a a0] -> Encoding # | |
ToJSON a => ToJSON1 (These a) | Since: aeson-1.5.1.0 |
Defined in Data.Aeson.Types.ToJSON liftToJSON :: (a0 -> Value) -> ([a0] -> Value) -> These a a0 -> Value # liftToJSONList :: (a0 -> Value) -> ([a0] -> Value) -> [These a a0] -> Value # liftToEncoding :: (a0 -> Encoding) -> ([a0] -> Encoding) -> These a a0 -> Encoding # liftToEncodingList :: (a0 -> Encoding) -> ([a0] -> Encoding) -> [These a a0] -> Encoding # | |
(ToJSON a, ToJSON b) => ToJSON1 ((,,) a b) | |
Defined in Data.Aeson.Types.ToJSON liftToJSON :: (a0 -> Value) -> ([a0] -> Value) -> (a, b, a0) -> Value # liftToJSONList :: (a0 -> Value) -> ([a0] -> Value) -> [(a, b, a0)] -> Value # liftToEncoding :: (a0 -> Encoding) -> ([a0] -> Encoding) -> (a, b, a0) -> Encoding # liftToEncodingList :: (a0 -> Encoding) -> ([a0] -> Encoding) -> [(a, b, a0)] -> Encoding # | |
ToJSON a => ToJSON1 (Const a :: Type -> Type) | |
Defined in Data.Aeson.Types.ToJSON liftToJSON :: (a0 -> Value) -> ([a0] -> Value) -> Const a a0 -> Value # liftToJSONList :: (a0 -> Value) -> ([a0] -> Value) -> [Const a a0] -> Value # liftToEncoding :: (a0 -> Encoding) -> ([a0] -> Encoding) -> Const a a0 -> Encoding # liftToEncodingList :: (a0 -> Encoding) -> ([a0] -> Encoding) -> [Const a a0] -> Encoding # | |
ToJSON1 (Tagged a) | |
Defined in Data.Aeson.Types.ToJSON liftToJSON :: (a0 -> Value) -> ([a0] -> Value) -> Tagged a a0 -> Value # liftToJSONList :: (a0 -> Value) -> ([a0] -> Value) -> [Tagged a a0] -> Value # liftToEncoding :: (a0 -> Encoding) -> ([a0] -> Encoding) -> Tagged a a0 -> Encoding # liftToEncodingList :: (a0 -> Encoding) -> ([a0] -> Encoding) -> [Tagged a a0] -> Encoding # | |
(ToJSON1 f, ToJSON1 g) => ToJSON1 (These1 f g) | Since: aeson-1.5.1.0 |
Defined in Data.Aeson.Types.ToJSON liftToJSON :: (a -> Value) -> ([a] -> Value) -> These1 f g a -> Value # liftToJSONList :: (a -> Value) -> ([a] -> Value) -> [These1 f g a] -> Value # liftToEncoding :: (a -> Encoding) -> ([a] -> Encoding) -> These1 f g a -> Encoding # liftToEncodingList :: (a -> Encoding) -> ([a] -> Encoding) -> [These1 f g a] -> Encoding # | |
(ToJSON a, ToJSON b, ToJSON c) => ToJSON1 ((,,,) a b c) | |
Defined in Data.Aeson.Types.ToJSON liftToJSON :: (a0 -> Value) -> ([a0] -> Value) -> (a, b, c, a0) -> Value # liftToJSONList :: (a0 -> Value) -> ([a0] -> Value) -> [(a, b, c, a0)] -> Value # liftToEncoding :: (a0 -> Encoding) -> ([a0] -> Encoding) -> (a, b, c, a0) -> Encoding # liftToEncodingList :: (a0 -> Encoding) -> ([a0] -> Encoding) -> [(a, b, c, a0)] -> Encoding # | |
(ToJSON1 f, ToJSON1 g) => ToJSON1 (Product f g) | |
Defined in Data.Aeson.Types.ToJSON liftToJSON :: (a -> Value) -> ([a] -> Value) -> Product f g a -> Value # liftToJSONList :: (a -> Value) -> ([a] -> Value) -> [Product f g a] -> Value # liftToEncoding :: (a -> Encoding) -> ([a] -> Encoding) -> Product f g a -> Encoding # liftToEncodingList :: (a -> Encoding) -> ([a] -> Encoding) -> [Product f g a] -> Encoding # | |
(ToJSON1 f, ToJSON1 g) => ToJSON1 (Sum f g) | |
Defined in Data.Aeson.Types.ToJSON liftToJSON :: (a -> Value) -> ([a] -> Value) -> Sum f g a -> Value # liftToJSONList :: (a -> Value) -> ([a] -> Value) -> [Sum f g a] -> Value # liftToEncoding :: (a -> Encoding) -> ([a] -> Encoding) -> Sum f g a -> Encoding # liftToEncodingList :: (a -> Encoding) -> ([a] -> Encoding) -> [Sum f g a] -> Encoding # | |
(ToJSON a, ToJSON b, ToJSON c, ToJSON d) => ToJSON1 ((,,,,) a b c d) | |
Defined in Data.Aeson.Types.ToJSON liftToJSON :: (a0 -> Value) -> ([a0] -> Value) -> (a, b, c, d, a0) -> Value # liftToJSONList :: (a0 -> Value) -> ([a0] -> Value) -> [(a, b, c, d, a0)] -> Value # liftToEncoding :: (a0 -> Encoding) -> ([a0] -> Encoding) -> (a, b, c, d, a0) -> Encoding # liftToEncodingList :: (a0 -> Encoding) -> ([a0] -> Encoding) -> [(a, b, c, d, a0)] -> Encoding # | |
(ToJSON1 f, ToJSON1 g) => ToJSON1 (Compose f g) | |
Defined in Data.Aeson.Types.ToJSON liftToJSON :: (a -> Value) -> ([a] -> Value) -> Compose f g a -> Value # liftToJSONList :: (a -> Value) -> ([a] -> Value) -> [Compose f g a] -> Value # liftToEncoding :: (a -> Encoding) -> ([a] -> Encoding) -> Compose f g a -> Encoding # liftToEncodingList :: (a -> Encoding) -> ([a] -> Encoding) -> [Compose f g a] -> Encoding # | |
(ToJSON a, ToJSON b, ToJSON c, ToJSON d, ToJSON e) => ToJSON1 ((,,,,,) a b c d e) | |
Defined in Data.Aeson.Types.ToJSON liftToJSON :: (a0 -> Value) -> ([a0] -> Value) -> (a, b, c, d, e, a0) -> Value # liftToJSONList :: (a0 -> Value) -> ([a0] -> Value) -> [(a, b, c, d, e, a0)] -> Value # liftToEncoding :: (a0 -> Encoding) -> ([a0] -> Encoding) -> (a, b, c, d, e, a0) -> Encoding # liftToEncodingList :: (a0 -> Encoding) -> ([a0] -> Encoding) -> [(a, b, c, d, e, a0)] -> Encoding # | |
(ToJSON a, ToJSON b, ToJSON c, ToJSON d, ToJSON e, ToJSON f) => ToJSON1 ((,,,,,,) a b c d e f) | |
Defined in Data.Aeson.Types.ToJSON liftToJSON :: (a0 -> Value) -> ([a0] -> Value) -> (a, b, c, d, e, f, a0) -> Value # liftToJSONList :: (a0 -> Value) -> ([a0] -> Value) -> [(a, b, c, d, e, f, a0)] -> Value # liftToEncoding :: (a0 -> Encoding) -> ([a0] -> Encoding) -> (a, b, c, d, e, f, a0) -> Encoding # liftToEncodingList :: (a0 -> Encoding) -> ([a0] -> Encoding) -> [(a, b, c, d, e, f, a0)] -> Encoding # | |
(ToJSON a, ToJSON b, ToJSON c, ToJSON d, ToJSON e, ToJSON f, ToJSON g) => ToJSON1 ((,,,,,,,) a b c d e f g) | |
Defined in Data.Aeson.Types.ToJSON liftToJSON :: (a0 -> Value) -> ([a0] -> Value) -> (a, b, c, d, e, f, g, a0) -> Value # liftToJSONList :: (a0 -> Value) -> ([a0] -> Value) -> [(a, b, c, d, e, f, g, a0)] -> Value # liftToEncoding :: (a0 -> Encoding) -> ([a0] -> Encoding) -> (a, b, c, d, e, f, g, a0) -> Encoding # liftToEncodingList :: (a0 -> Encoding) -> ([a0] -> Encoding) -> [(a, b, c, d, e, f, g, a0)] -> Encoding # | |
(ToJSON a, ToJSON b, ToJSON c, ToJSON d, ToJSON e, ToJSON f, ToJSON g, ToJSON h) => ToJSON1 ((,,,,,,,,) a b c d e f g h) | |
Defined in Data.Aeson.Types.ToJSON liftToJSON :: (a0 -> Value) -> ([a0] -> Value) -> (a, b, c, d, e, f, g, h, a0) -> Value # liftToJSONList :: (a0 -> Value) -> ([a0] -> Value) -> [(a, b, c, d, e, f, g, h, a0)] -> Value # liftToEncoding :: (a0 -> Encoding) -> ([a0] -> Encoding) -> (a, b, c, d, e, f, g, h, a0) -> Encoding # liftToEncodingList :: (a0 -> Encoding) -> ([a0] -> Encoding) -> [(a, b, c, d, e, f, g, h, a0)] -> Encoding # | |
(ToJSON a, ToJSON b, ToJSON c, ToJSON d, ToJSON e, ToJSON f, ToJSON g, ToJSON h, ToJSON i) => ToJSON1 ((,,,,,,,,,) a b c d e f g h i) | |
Defined in Data.Aeson.Types.ToJSON liftToJSON :: (a0 -> Value) -> ([a0] -> Value) -> (a, b, c, d, e, f, g, h, i, a0) -> Value # liftToJSONList :: (a0 -> Value) -> ([a0] -> Value) -> [(a, b, c, d, e, f, g, h, i, a0)] -> Value # liftToEncoding :: (a0 -> Encoding) -> ([a0] -> Encoding) -> (a, b, c, d, e, f, g, h, i, a0) -> Encoding # liftToEncodingList :: (a0 -> Encoding) -> ([a0] -> Encoding) -> [(a, b, c, d, e, f, g, h, i, a0)] -> Encoding # | |
(ToJSON a, ToJSON b, ToJSON c, ToJSON d, ToJSON e, ToJSON f, ToJSON g, ToJSON h, ToJSON i, ToJSON j) => ToJSON1 ((,,,,,,,,,,) a b c d e f g h i j) | |
Defined in Data.Aeson.Types.ToJSON liftToJSON :: (a0 -> Value) -> ([a0] -> Value) -> (a, b, c, d, e, f, g, h, i, j, a0) -> Value # liftToJSONList :: (a0 -> Value) -> ([a0] -> Value) -> [(a, b, c, d, e, f, g, h, i, j, a0)] -> Value # liftToEncoding :: (a0 -> Encoding) -> ([a0] -> Encoding) -> (a, b, c, d, e, f, g, h, i, j, a0) -> Encoding # liftToEncodingList :: (a0 -> Encoding) -> ([a0] -> Encoding) -> [(a, b, c, d, e, f, g, h, i, j, a0)] -> Encoding # | |
(ToJSON a, ToJSON b, ToJSON c, ToJSON d, ToJSON e, ToJSON f, ToJSON g, ToJSON h, ToJSON i, ToJSON j, ToJSON k) => ToJSON1 ((,,,,,,,,,,,) a b c d e f g h i j k) | |
Defined in Data.Aeson.Types.ToJSON liftToJSON :: (a0 -> Value) -> ([a0] -> Value) -> (a, b, c, d, e, f, g, h, i, j, k, a0) -> Value # liftToJSONList :: (a0 -> Value) -> ([a0] -> Value) -> [(a, b, c, d, e, f, g, h, i, j, k, a0)] -> Value # liftToEncoding :: (a0 -> Encoding) -> ([a0] -> Encoding) -> (a, b, c, d, e, f, g, h, i, j, k, a0) -> Encoding # liftToEncodingList :: (a0 -> Encoding) -> ([a0] -> Encoding) -> [(a, b, c, d, e, f, g, h, i, j, k, a0)] -> Encoding # | |
(ToJSON a, ToJSON b, ToJSON c, ToJSON d, ToJSON e, ToJSON f, ToJSON g, ToJSON h, ToJSON i, ToJSON j, ToJSON k, ToJSON l) => ToJSON1 ((,,,,,,,,,,,,) a b c d e f g h i j k l) | |
Defined in Data.Aeson.Types.ToJSON liftToJSON :: (a0 -> Value) -> ([a0] -> Value) -> (a, b, c, d, e, f, g, h, i, j, k, l, a0) -> Value # liftToJSONList :: (a0 -> Value) -> ([a0] -> Value) -> [(a, b, c, d, e, f, g, h, i, j, k, l, a0)] -> Value # liftToEncoding :: (a0 -> Encoding) -> ([a0] -> Encoding) -> (a, b, c, d, e, f, g, h, i, j, k, l, a0) -> Encoding # liftToEncodingList :: (a0 -> Encoding) -> ([a0] -> Encoding) -> [(a, b, c, d, e, f, g, h, i, j, k, l, a0)] -> Encoding # | |
(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) => ToJSON1 ((,,,,,,,,,,,,,) a b c d e f g h i j k l m) | |
Defined in Data.Aeson.Types.ToJSON liftToJSON :: (a0 -> Value) -> ([a0] -> Value) -> (a, b, c, d, e, f, g, h, i, j, k, l, m, a0) -> Value # liftToJSONList :: (a0 -> Value) -> ([a0] -> Value) -> [(a, b, c, d, e, f, g, h, i, j, k, l, m, a0)] -> Value # liftToEncoding :: (a0 -> Encoding) -> ([a0] -> Encoding) -> (a, b, c, d, e, f, g, h, i, j, k, l, m, a0) -> Encoding # liftToEncodingList :: (a0 -> Encoding) -> ([a0] -> Encoding) -> [(a, b, c, d, e, f, g, h, i, j, k, l, m, a0)] -> Encoding # | |
(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) => ToJSON1 ((,,,,,,,,,,,,,,) a b c d e f g h i j k l m n) | |
Defined in Data.Aeson.Types.ToJSON liftToJSON :: (a0 -> Value) -> ([a0] -> Value) -> (a, b, c, d, e, f, g, h, i, j, k, l, m, n, a0) -> Value # liftToJSONList :: (a0 -> Value) -> ([a0] -> Value) -> [(a, b, c, d, e, f, g, h, i, j, k, l, m, n, a0)] -> Value # liftToEncoding :: (a0 -> Encoding) -> ([a0] -> Encoding) -> (a, b, c, d, e, f, g, h, i, j, k, l, m, n, a0) -> Encoding # liftToEncodingList :: (a0 -> Encoding) -> ([a0] -> Encoding) -> [(a, b, c, d, e, f, g, h, i, j, k, l, m, n, a0)] -> Encoding # |
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
(ormzero
) 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 writeText
literals. {-# LANGUAGE OverloadedStrings #-} data Coord = Coord { x :: Double, y :: Double } instanceFromJSON
Coord whereparseJSON
(Object
v) = Coord<$>
v.:
"x"<*>
v.:
"y" -- We do not expect a non-Object
value here. -- We could useempty
to fail, buttypeMismatch
-- 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:
instanceFromJSON
Coord whereparseJSON
=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
clause to your
datatype and declare a Generic
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 } derivingGeneric
instanceFromJSON
Coord
The default implementation will be equivalent to
parseJSON =
; if you need different
options, you can customize the generic decoding by defining:genericParseJSON
defaultOptions
customOptions =defaultOptions
{fieldLabelModifier
=map
toUpper
} instanceFromJSON
Coord whereparseJSON
=genericParseJSON
customOptions
Instances
class FromJSON1 (f :: Type -> Type) #
Lifting of the FromJSON
class to unary type constructors.
Instead of manually writing your FromJSON1
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
liftParseJSON
.
To use the second, simply add a deriving
clause to your
datatype and declare a Generic1
FromJSON1
instance for your datatype without giving
a definition for liftParseJSON
.
For example:
{-# LANGUAGE DeriveGeneric #-} import GHC.Generics data Pair a b = Pair { pairFst :: a, pairSnd :: b } derivingGeneric1
instanceFromJSON
a =>FromJSON1
(Pair a)
If the default implementation doesn't give exactly the results you want,
you can customize the generic decoding with only a tiny amount of
effort, using genericLiftParseJSON
with your preferred Options
:
customOptions =defaultOptions
{fieldLabelModifier
=map
toUpper
} instanceFromJSON
a =>FromJSON1
(Pair a) whereliftParseJSON
=genericLiftParseJSON
customOptions
Instances
Options that specify how to encode/decode your datatype to/from JSON.
Options can be set using record syntax on defaultOptions
with the fields
below.
Class for string-like datastructures; used by the overloaded string extension (-XOverloadedStrings in GHC).
fromString :: String -> a #
Instances
64-bit unsigned integer type
Instances
module GHC.Generics