| Safe Haskell | None |
|---|
Data.Aeson.TH.Smart
Documentation
Arguments
| :: (String -> String) | Function to change field names. |
| -> 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. |
| -> Name | Name of the type for which to generate a |
| -> Q [Dec] |
Generates a ToJSON instance declaration for the given data type.
Example:
data Foo = FooCharInt$(deriveToJSONid''Foo)
This will splice in the following code:
instanceToJSONFoo wheretoJSON= value -> case value of Foo arg1 arg2 ->Array$create$ do mv <-unsafeNew2unsafeWritemv 0 (toJSONarg1)unsafeWritemv 1 (toJSONarg2) return mv
Arguments
| :: (String -> String) | Function to change field names. |
| -> 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