codec-0.2: Simple bidirectional serialization

Safe HaskellNone
LanguageHaskell2010

Data.Aeson.Codec

Contents

Synopsis

Documentation

data JSONCodec a Source #

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

Constructors

JSONCodec 

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

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

JSON object codecs

type ObjectCodec a = Codec ObjectParser ObjectBuilder a Source #

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.

field' :: Text -> JSONCodec a -> ObjectCodec a Source #

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

asObject :: String -> ObjectCodec a -> JSONCodec a Source #

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

JSON array codecs

type ArrayCodec a = Codec ArrayParser ArrayBuilder a Source #

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.

element' :: JSONCodec a -> ArrayCodec a Source #

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

asArray :: String -> ArrayCodec a -> JSONCodec a Source #

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.