Safe Haskell | Safe-Inferred |
---|---|
Language | GHC2021 |
Synopsis
- parseErrorTree :: Error -> ParseError ErrorTree -> ErrorTree
- 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))
- test_keyRenamed :: Spec
- data EmptyObject = EmptyObject
- jsonArray :: [Value] -> Value
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 #
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 # |