Module

Data.Codec.Argonaut.Compat

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

Codecs that are compatible with purescript-argonaut-codecs.

#maybe Source

maybe :: forall a. JsonCodec a -> JsonCodec (Maybe a)

A codec for Maybe values.

Note: this codec cannot represent nested Maybe values in a lossless manner.

#strMap Source

strMap :: forall a. JsonCodec a -> JsonCodec (StrMap a)

A codec for StrMap values.

Encodes as a JSON object with the keys as properties.

Re-exports from Data.Codec.Argonaut

#JsonCodec Source

type JsonCodec a = BasicCodec (Either JsonDecodeError) Json a

Codec type for Json values.

#JPropCodec Source

type JPropCodec a = Codec (Either JsonDecodeError) JObject (List JAssoc) a a

Codec type for JObject prop/value pairs.

#JIndexedCodec Source

type JIndexedCodec a = Codec (Either JsonDecodeError) JArray (List Json) a a

Codec type for specifically indexed JArray elements.

#string Source

string :: JsonCodec String

A codec for String values in Json.

#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.

#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

#prop Source

prop :: forall a. String -> JsonCodec a -> JPropCodec a

A codec for a property of an object.

#printJsonDecodeError Source

printJsonDecodeError :: JsonDecodeError -> String

Prints a JsonDecodeError as a somewhat readable error message.

#object Source

object :: forall a. String -> JPropCodec a -> JsonCodec a

A codec for objects that are encoded with specific properties.

#number Source

number :: JsonCodec Number

A codec for Number values in Json.

#null Source

null :: JsonCodec JNull

A codec for null values in Json.

#json Source

json :: JsonCodec Json

The "identity codec" for Json values.

#jobject Source

jobject :: JsonCodec JObject

A codec for JObject values in Json.

#jarray Source

jarray :: JsonCodec JArray

A codec for a JArray values in Json. This does not decode the values of the array, for that use array for a general array decoder, or indexedArray with index to decode fixed length array encodings.

#int Source

int :: JsonCodec Int

A codec for Int values in Json.

#indexedArray Source

indexedArray :: forall a. String -> JIndexedCodec a -> JsonCodec a

A codec for types that are encoded as an array with a specific layout.

#index Source

index :: forall a. Int -> JsonCodec a -> JIndexedCodec a

A codec for an item in an indexedArray.

#encode Source

encode :: forall d c b a m. Codec m a b c d -> c -> b

#decode Source

decode :: forall d c b a m. Codec m a b c d -> a -> m d

#char Source

char :: JsonCodec Char

A codec for Char values in Json.

#boolean Source

boolean :: JsonCodec Boolean

A codec for Boolean values in Json.

#array Source

array :: forall a. JsonCodec a -> JsonCodec (Array a)

A codec for Array values.

#(~) 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

#(<~<) Source

Operator alias for Data.Codec.composeCodec (right-associative / precedence 8)

Re-exports from Data.Codec.Argonaut.Common

#tuple Source

tuple :: forall b a. JsonCodec a -> JsonCodec b -> JsonCodec (Tuple a b)

A codec for Tuple values.

Encodes as a two-element array in JSON.

#map Source

map :: forall b a. Ord a => JsonCodec a -> JsonCodec b -> JsonCodec (Map a b)

A codec for Map values.

Encodes as an array of two-element key/value arrays in JSON.

#list Source

list :: forall a. JsonCodec a -> JsonCodec (List a)

A codec for List values.

Encodes as an array in JSON.

#either Source

either :: forall b a. JsonCodec a -> JsonCodec b -> JsonCodec (Either a b)

A codec for Either values.