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

Json

Synopsis

Documentation

toParseJSON Source #

Arguments

:: Parse Error a

the error type is Error, if you need ErrorTree use toParseJSONErrorTree

-> Value 
-> Parser a 

Use a Data.Aeson.BetterErrors parser to implement FromJSON’s parseJSON method.

instance FromJSON Foo where
  parseJSON = Json.toParseJSON parseFoo

toParseJSONErrorTree Source #

Arguments

:: Parse ErrorTree a

the error type is ErrorTree, if you need Error use toParseJSON

-> Value 
-> Parser a 

Use a Data.Aeson.BetterErrors parser to implement FromJSON’s parseJSON method.

instance FromJSON Foo where
  parseJSON = Json.toParseJSON parseFoo

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

asErrorTree :: Functor m => ParseT Error m a -> ParseT ErrorTree m a Source #

Lift the parser error to an error tree

asArraySet :: (Ord a, Monad m) => ParseT err m a -> ParseT err m (Set a) Source #

Parse the json array into a Set.

asObjectMap :: Monad m => ParseT err m a -> ParseT err m (Map Text a) Source #

Parse the json object into a Map.

countArrayElements :: Monad m => ParseT Error m Natural Source #

Parse as json array and count the number of elements in the array.

asUtcTime :: Monad m => ParseT Error m UTCTime Source #

Json string containing a UTC timestamp, yyyy-mm-ddThh:mm:ss[.sss]Z (ISO 8601:2004(E) sec. 4.3.2 extended format)

asUtcTimeLenient :: Monad m => ParseT Error m UTCTime Source #

Json string containing a UTC timestamp. | Accepts multiple timezone formats. Do not use this if you can force the input to use the Z UTC notation (e.g. in a CSV), use utcTime instead.

Accepts

  • UTC timestamps: yyyy-mm-ddThh:mm:ss[.sss]Z
  • timestamps with time zone: yyyy-mm-ddThh:mm:ss[.sss]±hh:mm

( both ISO 8601:2004(E) sec. 4.3.2 extended format)

The time zone of the second kind of timestamp is taken into account, but normalized to UTC (it’s not preserved what the original time zone was)

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

mkJsonArray :: [Value] -> Value Source #

Create a json array from a list of json values.