composite-aeson-0.5.1.0: JSON for Vinyl/Frames records

Safe HaskellNone
LanguageHaskell2010

Composite.Aeson.Formats.Generic

Synopsis

Documentation

abeJsonFormat :: ToJSON a => Parse e a -> JsonFormat e a Source #

Produce an explicit JsonFormat by using the implicit Aeson ToJSON instance and an explicit aeson-better-errors Parse.

aesonJsonFormat :: (ToJSON a, FromJSON a) => JsonFormat e a Source #

Produce an explicit JsonFormat by using the implicit Aeson FromJSON and ToJSON instances.

If an aeson-better-errors parser is available for a, it's probably better to use abeJsonFormat to get the enhanced error reporting.

jsonArrayFormat :: (t -> [a]) -> ([a] -> Parse e t) -> JsonFormat e a -> JsonFormat e t Source #

JsonFormat for any type which can be converted to/from a list which maps to a JSON array.

jsonObjectFormat :: (t -> [(Text, a)]) -> ([(Text, a)] -> Parse e t) -> JsonFormat e a -> JsonFormat e t Source #

JsonFormat for any type which can be converted to/from a list of pairs which maps to a JSON object.

data SumStyle Source #

Constructors

SumStyleFieldName

Map to a single-field object with the field name determined by the sum branch and the field value being the encoded value for that branch.

SumStyleTypeValue Text Text

Map to a two-field object with fixed field names, the first being the type field and the second beind the value field.

SumStyleMergeType Text

Given that each sum branch maps to a JSON object, add/parse an additional field to that object with the given name.

jsonSumFormat :: SumStyle -> (a -> (Text, Value)) -> NonEmpty (Text, FromJson e a) -> JsonFormat e a Source #

JsonFormat which maps sum types to JSON according to SumStyle, given a pair of functions to decompose and recompose the sum type.