| Safe Haskell | None |
|---|
Data.Aeson.TH.Smart
Documentation
Arguments
| :: (String -> String) | Function to change field names. |
| -> Bool | Whether to require JSON instances for type variables |
| -> Name | Name of the type for which to generate |
| -> Q [Dec] |
Generates both ToJSON and FromJSON instance declarations for the given
data type.
This is a convienience function which is equivalent to calling both
deriveToJSON and deriveFromJSON.
Arguments
| :: (String -> String) | Function to change field names. |
| -> Bool | Whether to require FromJSON instances for type variables |
| -> Name | Name of the type for which to generate a |
| -> Q [Dec] |
Generates a FromJSON instance declaration for the given data type.
Example:
data Foo = Foo Char Int
$(deriveFromJSON id ''Foo)
This will splice in the following code:
instanceFromJSONFoo whereparseJSON= value -> case value ofArrayarr -> if (V.length arr == 2) then Foo <$>parseJSON(arrunsafeIndex0) <*>parseJSON(arrunsafeIndex1) else fail "<error message>" other -> fail "<error message>"
Arguments
| :: (String -> String) | Function to change field names. |
| -> Name | Name of the encoded type. |
| -> Q Exp |
Generates a lambda expression which parses the JSON encoding of the given data type.
Example:
data Foo = Foo Int
parseFoo ::Value->ParserFoo parseFoo = $(mkParseJSONid ''Foo)
This will splice in the following code:
\value -> case value of arg -> Foo <$> parseJSON arg