Safe Haskell | Safe-Inferred |
---|---|
Language | GHC2021 |
Synopsis
- toParseJSON :: Parse Error a -> Value -> Parser a
- toParseJSONErrorTree :: Parse ErrorTree a -> Value -> Parser a
- parseErrorTree :: Error -> ParseError ErrorTree -> ErrorTree
- asErrorTree :: Functor m => ParseT Error m a -> ParseT ErrorTree m a
- asArraySet :: (Ord a, Monad m) => ParseT err m a -> ParseT err m (Set a)
- asObjectMap :: Monad m => ParseT err m a -> ParseT err m (Map Text a)
- countArrayElements :: Monad m => ParseT Error m Natural
- asUtcTime :: Monad m => ParseT Error m UTCTime
- asUtcTimeLenient :: Monad m => ParseT Error m UTCTime
- keyLabel :: forall label err m a. Monad m => Text -> ParseT err m a -> ParseT err m (Label label a)
- keyLabel' :: forall label err m a. Monad m => Proxy label -> Text -> ParseT err m a -> ParseT err m (Label label a)
- keyLabelMay :: forall label err m a. Monad m => Text -> ParseT err m a -> ParseT err m (Label label (Maybe a))
- keyLabelMay' :: forall label err m a. Monad m => Proxy label -> Text -> ParseT err m a -> ParseT err m (Label label (Maybe a))
- keyRenamed :: Monad m => NonEmpty Text -> ParseT err m a -> ParseT err m a
- keyRenamedMay :: Monad m => NonEmpty Text -> ParseT err m a -> ParseT err m (Maybe a)
- keyRenamedTryOldKeys :: Monad m => [Text] -> ParseT err m a -> ParseT err m (Maybe (ParseT err m a))
- data EmptyObject = EmptyObject
- mkJsonArray :: [Value] -> Value
Documentation
:: Parse Error a | the error type is |
-> Value | |
-> Parser a |
Use a Data.Aeson.BetterErrors parser to implement FromJSON
’s parseJSON
method.
instance FromJSON Foo where parseJSON = Json.toParseJSON parseFoo
:: Parse ErrorTree a | the error type is |
-> 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 #
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
Instances
FromJSON EmptyObject Source # | |
Defined in Json parseJSON :: Value -> Parser EmptyObject # parseJSONList :: Value -> Parser [EmptyObject] # | |
ToJSON EmptyObject Source # | |
Defined in Json toJSON :: EmptyObject -> Value # toEncoding :: EmptyObject -> Encoding # toJSONList :: [EmptyObject] -> Value # toEncodingList :: [EmptyObject] -> Encoding # | |
Show EmptyObject Source # | |
Defined in Json showsPrec :: Int -> EmptyObject -> ShowS # show :: EmptyObject -> String # showList :: [EmptyObject] -> ShowS # | |
Eq EmptyObject Source # | |
Defined in Json (==) :: EmptyObject -> EmptyObject -> Bool # (/=) :: EmptyObject -> EmptyObject -> Bool # |
mkJsonArray :: [Value] -> Value Source #
Create a json array from a list of json values.