Module

Data.Codec.JSON.Record

Package
purescript-codec-json
Repository
garyb/purescript-codec-json

#object Source

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

Constructs a Codec for a Record from a record of codecs.

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

personCodec ∷ CJ.Codec Person
personCodec = CAR.object { name: CJ.string, age: CJ.int }

#record Source

record :: forall ri ro rl. RowToList ri rl => RowListCodec rl ri ro => Record ri -> PropCodec (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 Codec 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. Codec 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