codec-0.1: First-class record construction and bidirectional serialization

Safe HaskellNone
LanguageHaskell2010

Data.Aeson.Codec

Contents

Synopsis

JSON codecs

type JSONCodec a = ConcreteCodec Value Parser a

JSON codec. This is just a ToJSON/FromJSON implementation wrapped up in newtypes. Use def to get a JSONCodec for a ToJSON/FromJSON instance.

JSON object codecs

type ObjectParser = ReaderT Object Parser

type ObjectBuilder = Const (Endo [Pair])

type ObjectCodec a = Codec ObjectParser ObjectBuilder a

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

entry :: Text -> JSONCodec a -> ObjectCodec a

Read/write a given value from/to a given key in the current object, using a given sub-codec. ObjectCodec's IsString instance is equal to entry def.

pair :: ToJSON a => Text -> a -> ObjectBuilder ()

Produce a key-value pair.

obj :: String -> ObjectCodec a -> JSONCodec a

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