codec-0.2.1: Simple bidirectional serialization

Data.Aeson.Codec

Synopsis

Documentation

data JSONCodec a Source #

Describes the de/serialization of a type a. Equivalent to a ToJSON and a FromJSON instance.

Constructors

 JSONCodec FieldsparseJSONCodec :: Value -> Parser a toJSONCodec :: a -> Value toEncodingCodec :: a -> Encoding

defJSON :: (FromJSON a, ToJSON a) => JSONCodec a Source #

Encode/decode a value with its ToJSON and FromJSON instances.

JSON object codecs

A codec that parses values out of a given Object, and produces key-value pairs into a new one.

field :: (FromJSON a, ToJSON a) => Text -> ObjectCodec a Source #

Store/retrieve a value in a given JSON field, with the default JSON serialization.

Store/retrieve a value in a given JSON field, with a given JSONCodec.

Turn an ObjectCodec into a JSONCodec with an expected name (see withObject).

JSON array codecs

A codec that serializes data to a sequence of JSON array elements.

element :: (FromJSON a, ToJSON a) => ArrayCodec a Source #

Expect/append an array element, using the default serialization.

Expect/append an array element, using a given JSONCodec.

A codec that parses values out of a given Array, and produces key-value pairs into a new one.

arrayOf :: (FromJSON b, ToJSON b) => (a -> [b]) -> ([b] -> a) -> JSONCodec a Source #

Given a a way to turn a into [ b ] and back, create a JSONCodec for a.

arrayOf' :: (a -> [b]) -> ([b] -> a) -> JSONCodec b -> JSONCodec a Source #

Given a JSONCodec for b and a way to turn a into [ b ] and back, create a JSONCodec for a.