Module

Data.Codec.Argonaut.Record

Package
purescript-codec-argonaut
Repository
garyb/purescript-codec-argonaut

#object Source

object :: forall ri ro rl. RowToList ri rl => RowListCodec rl ri ro => String -> Record ri -> JsonCodec (Record ro)

Constructs a JsonCodec for a Record from a name and a record of codecs. The name is used in the error message produced when decoding fails.

type Person = { name ∷ String, age ∷ Int }

personCodec ∷ CA.JsonCodec Person
personCodec = CAR.object "Person" { name: CA.string, age: CA.int }

#record Source

record :: forall ri ro rl. RowToList ri rl => RowListCodec rl ri ro => Record ri -> JPropCodec (Record ro)

Constructs a JPropCodec for a Record from a record of codecs. Commonly the object function in this module will be the preferred choice, as that produces a JsonCodec instead.

#Optional Source

newtype Optional a

Used to wrap codec values provided in record to indicate the field is optional.

This will only decode the property as Nothing if the field does not exist in the object - having a values such as null assigned will need handling separately.

The property will be omitted when encoding and the value is Nothing.

Constructors

Instances

#optional Source

optional :: forall a. JsonCodec a -> Optional a

A lowercase alias for Optional, provided for stylistic reasons only.

#RowListCodec Source

class RowListCodec :: RowList Type -> Row Type -> Row Type -> Constraintclass RowListCodec (rl :: RowList Type) (ri :: Row Type) (ro :: Row Type) | rl -> ri ro where

The class used to enable the building of Record codecs by providing a record of codecs.

Members

Instances