Safe Haskell | None |
---|---|
Language | Haskell98 |
Synopsis
- type Value = SomeValue Immutable
- type Object = SomeObject Immutable
- data Options
- defaultOptions :: Options
- data SumEncoding
- defaultTaggedObject :: SumEncoding
- camelTo :: Char -> String -> String
Documentation
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.
Default encoding Options
:
Options
{fieldLabelModifier
= id ,constructorTagModifier
= id ,allNullaryToStringTag
= True ,omitNothingFields
= False ,sumEncoding
=defaultTaggedObject
,unwrapUnaryRecords
= False ,tagSingleConstructors
= False }
data SumEncoding #
Specifies how to encode constructors of a sum datatype.
TaggedObject | A constructor will be encoded to an object with a field
|
UntaggedValue | Constructor names won't be encoded. Instead only the contents of the constructor will be encoded as if the type had a single constructor. JSON encodings have to be disjoint for decoding to work properly. When decoding, constructors are tried in the order of definition. If some encodings overlap, the first one defined will succeed. Note: Nullary constructors are encoded as strings (using
Note: Only the last error is kept when decoding, so in the case of malformed JSON, only an error for the last constructor will be reported. |
ObjectWithSingleField | A constructor will be encoded to an object with a single
field named after the constructor tag (modified by the
|
TwoElemArray | A constructor will be encoded to a 2-element array where the
first element is the tag of the constructor (modified by the
|
Instances
Eq SumEncoding | |
Defined in Data.Aeson.Types.Internal (==) :: SumEncoding -> SumEncoding -> Bool # (/=) :: SumEncoding -> SumEncoding -> Bool # | |
Show SumEncoding | |
Defined in Data.Aeson.Types.Internal showsPrec :: Int -> SumEncoding -> ShowS # show :: SumEncoding -> String # showList :: [SumEncoding] -> ShowS # |
defaultTaggedObject :: SumEncoding #
Default TaggedObject
SumEncoding
options:
defaultTaggedObject =TaggedObject
{tagFieldName
= "tag" ,contentsFieldName
= "contents" }
camelTo :: Char -> String -> String #
Converts from CamelCase to another lower case, interspersing
the character between all capital letters and their previous
entries, except those capital letters that appear together,
like API
.
For use by Aeson template haskell calls.
camelTo '_' 'CamelCaseAPI' == "camel_case_api"