Data.Codec.Argonaut
- Package
- purescript-codec-argonaut
- Repository
- garyb/purescript-codec-argonaut
#JsonCodec Source
type JsonCodec a = BasicCodec (Either JsonDecodeError) Json aCodec type for Json values.
#JsonDecodeError Source
data JsonDecodeErrorError type for failures while decoding.
Constructors
TypeMismatch StringUnexpectedValue JsonAtIndex Int JsonDecodeErrorAtKey String JsonDecodeErrorNamed String JsonDecodeErrorMissingValue
Instances
#printJsonDecodeError Source
printJsonDecodeError :: JsonDecodeError -> StringPrints a JsonDecodeError as a somewhat readable error message.
#JIndexedCodec Source
type JIndexedCodec a = Codec (Either JsonDecodeError) JArray (List Json) a aCodec type for specifically indexed JArray elements.
#indexedArray Source
indexedArray :: forall a. String -> JIndexedCodec a -> JsonCodec aA codec for types that are encoded as an array with a specific layout.
#index Source
index :: forall a. Int -> JsonCodec a -> JIndexedCodec aA codec for an item in an indexedArray.
#JPropCodec Source
type JPropCodec a = Codec (Either JsonDecodeError) JObject (List JAssoc) a aCodec type for JObject prop/value pairs.
#object Source
object :: forall a. String -> JPropCodec a -> JsonCodec aA codec for objects that are encoded with specific properties.
#prop Source
prop :: forall a. String -> JsonCodec a -> JPropCodec aA codec for a property of an object.
#record Source
record :: JPropCodec (Record ())The starting value for a object-record codec. Used with recordProp it
provides a convenient method for defining codecs for record types that
encode into JSON objects of the same shape.
For example:
myRecordCodec =
object "MyRecord" $ record
# recordProp (SProxy :: SProxy "tag") tagCodec
# recordProp (SProxy :: SProxy "value") valueCodec
#recordProp Source
recordProp :: forall r' r a p. IsSymbol p => RowCons p a r r' => SProxy p -> JsonCodec a -> JPropCodec (Record r) -> JPropCodec (Record r')Used with record to define codecs for record types that encode into JSON
objects of the same shape. See the comment on record for an example.
Re-exports from Data.Codec
#(~) Source
Operator alias for Data.Profunctor.lmap (left-associative / precedence 5)
GCodec is defined as a Profunctor so that lmap can be used to target
specific fields when defining a codec for a product type. This operator
is a convenience for that:
tupleCodec =
Tuple
<$> fst ~ fstCodec
<*> snd ~ sndCodec