pa-json-0.2.1.0: Our JSON parsers/encoders
Safe HaskellSafe-Inferred
LanguageGHC2021

Json

Synopsis

Documentation

parseErrorTree :: Error -> ParseError ErrorTree -> ErrorTree Source #

Convert a ParseError to a corresponding ErrorTree

TODO: build a different version of displayError so that we can nest ErrorTree as well

keyLabel :: forall label err m a. Monad m => Text -> ParseT err m a -> ParseT err m (Label label a) Source #

Parse a key from the object, à la key, return a labelled value.

We don’t provide a version that infers the json object key, since that conflates internal naming with the external API, which is dangerous.

@ do txt <- keyLabel "myLabel" "jsonKeyName" Json.asText pure (txt :: Label "myLabel" Text) @@

keyLabel' :: forall label err m a. Monad m => Proxy label -> Text -> ParseT err m a -> ParseT err m (Label label a) Source #

Parse a key from the object, à la key, return a labelled value. Version of keyLabel that requires a proxy.

@ do txt <- keyLabel' (Proxy "myLabel") "jsonKeyName" Json.asText pure (txt :: Label "myLabel" Text) @@

keyLabelMay :: forall label err m a. Monad m => Text -> ParseT err m a -> ParseT err m (Label label (Maybe a)) Source #

Parse an optional key from the object, à la keyMay, return a labelled value.

We don’t provide a version that infers the json object key, since that conflates internal naming with the external API, which is dangerous.

@ do txt <- keyLabelMay "myLabel" "jsonKeyName" Json.asText pure (txt :: Label "myLabel" (Maybe Text)) @@

keyLabelMay' :: forall label err m a. Monad m => Proxy label -> Text -> ParseT err m a -> ParseT err m (Label label (Maybe a)) Source #

Parse an optional key from the object, à la keyMay, return a labelled value. Version of keyLabelMay that requires a proxy.

@ do txt <- keyLabelMay' (Proxy "myLabel") "jsonKeyName" Json.asText pure (txt :: Label "myLabel" (Maybe Text)) @@

keyRenamed :: Monad m => NonEmpty Text -> ParseT err m a -> ParseT err m a Source #

Like key, but allows a list of keys that are tried in order.

This is intended for renaming keys in an object. The first key is the most up-to-date version of a key, the others are for backward-compatibility.

If a key (new or old) exists, the inner parser will always be executed for that key.

keyRenamedMay :: Monad m => NonEmpty Text -> ParseT err m a -> ParseT err m (Maybe a) Source #

Like keyMay, but allows a list of keys that are tried in order.

This is intended for renaming keys in an object. The first key is the most up-to-date version of a key, the others are for backward-compatibility.

If a key (new or old) exists, the inner parser will always be executed for that key.

keyRenamedTryOldKeys :: Monad m => [Text] -> ParseT err m a -> ParseT err m (Maybe (ParseT err m a)) Source #

Helper function for keyRenamed and keyRenamedMay that returns the parser for the first old key that exists, if any.

data EmptyObject Source #

A simple type isomorphic to () that that transforms to an empty json object and parses

Constructors

EmptyObject 

Instances

Instances details
FromJSON EmptyObject Source # 
Instance details

Defined in Json

ToJSON EmptyObject Source # 
Instance details

Defined in Json

Show EmptyObject Source # 
Instance details

Defined in Json

Eq EmptyObject Source # 
Instance details

Defined in Json

jsonArray :: [Value] -> Value Source #

Create a json array from a list of json values.