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 aUsed 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
(RowListCodec rs ri' ro', Cons sym (Optional a) ri' ri, Cons sym (Maybe a) ro' ro, IsSymbol sym) => RowListCodec (Cons sym (Optional a) rs) ri ro
#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
rowListCodec :: forall proxy. proxy rl -> Record ri -> JPropCodec (Record ro)
Instances
RowListCodec Nil () ()(RowListCodec rs ri' ro', Cons sym (Optional a) ri' ri, Cons sym (Maybe a) ro' ro, IsSymbol sym) => RowListCodec (Cons sym (Optional a) rs) ri ro(RowListCodec rs ri' ro', Cons sym (JsonCodec a) ri' ri, Cons sym a ro' ro, IsSymbol sym) => RowListCodec (Cons sym (JsonCodec a) rs) ri ro