Json Codecs

Codecs

There are two critical aspects to codecs, encode a data type to json, and decode a data type from json. Encoding is handled by the `EncodeJson` type class. Decoding is handled by the `DecodeJson` type class. Both can be defined at once using the `CodecJson` type class.

EncodeJson

Defining an encode json instance is straight forward, you just need to provide a function that takes your type and produces a json object.

    

We also provide a set of very convenient methods for building EncodeJson instances.

    

DecodeJson

Defining a decode json instance is more involved, as you have to handle the chance of failure where you may not be able to decode your type.

`DecodeJson` works on a HCursor. This allows codecs to be combined whilst mainting efficiency and tracking cursor movements for nice error messages.

Defining a `DecodeJson` directly you need to build your data type from a cursor and return a DecodeResult.

    

We also provide a set of very convenient methods for building DecodeJson instances.

    

CodecJson

CodecJson allows you to construct both an encode and decode at the same time.

Defining a `CodecJson` you pass two arguments, the first is as per `EncodeJson`, the second is as per `DecodeJson`.

    

We also provide a set of very convenient methods for building CodecJson instances.