Data.Aeson.BetterErrors.Internal

aeson-better-errors-0.9.1.1: Better error messages when decoding JSON values.

Safe Haskell | None
Language | Haskell2010

Data.Aeson.BetterErrors.Internal

Synopsis

- newtype ParseT err (m :: Type -> Type) a = ParseT (ReaderT ParseReader (ExceptT (ParseError err) m) a)
- type Parse err a = ParseT err Identity a
- runParseT :: ParseT err m a -> Value -> m (Either (ParseError err) a)
- runParse :: Parse err a -> Value -> Either (ParseError err) a
- mapParseT :: forall err (m :: Type -> Type) a err' (m' :: Type -> Type) a'. (ReaderT ParseReader (ExceptT (ParseError err) m) a -> ReaderT ParseReader (ExceptT (ParseError err') m') a') -> ParseT err m a -> ParseT err' m' a'
- mapError :: forall (m :: Type -> Type) err err' a. Functor m => (err -> err') -> ParseT err m a -> ParseT err' m a
- (.!) :: forall (m :: Type -> Type) err a err'. Functor m => ParseT err m a -> (err -> err') -> ParseT err' m a
- (<|>) :: forall (m :: Type -> Type) err a. Monad m => ParseT err m a -> ParseT err m a -> ParseT err m a
- type Parse' a = Parse Void a
- runParserT :: Monad m => (s -> Either String Value) -> ParseT err m a -> s -> m (Either (ParseError err) a)
- runParser :: (s -> Either String Value) -> Parse err a -> s -> Either (ParseError err) a
- parseM :: Monad m => ParseT err m a -> ByteString -> m (Either (ParseError err) a)
- parse :: Parse err a -> ByteString -> Either (ParseError err) a
- parseStrictM :: Monad m => ParseT err m a -> ByteString -> m (Either (ParseError err) a)
- parseStrict :: Parse err a -> ByteString -> Either (ParseError err) a
- parseValueM :: Monad m => ParseT err m a -> Value -> m (Either (ParseError err) a)
- parseValue :: Parse err a -> Value -> Either (ParseError err) a
- toAesonParser :: (err -> Text) -> Parse err a -> Value -> Parser a
- toAesonParser' :: Parse' a -> Value -> Parser a
- fromAesonParser :: forall (m :: Type -> Type) a e. (Functor m, Monad m, FromJSON a) => ParseT e m a
- data ParseReader = ParseReader {
  - rdrPath :: DList PathPiece
  - rdrValue :: Value
  }
- appendPath :: PathPiece -> ParseReader -> ParseReader
- setValue :: Value -> ParseReader -> ParseReader
- data PathPiece
  - = ObjectKey Text
  - | ArrayIndex Int
- data ParseError err
  - = InvalidJSON String
  - | BadSchema [PathPiece] (ErrorSpecifics err)
- type ParseError' = ParseError Void
- data ErrorSpecifics err
  - = KeyMissing Text
  - | OutOfBounds Int
  - | WrongType JSONType Value
  - | ExpectedIntegral Double
  - | FromAeson String
  - | CustomError err
- type ErrorSpecifics' = ErrorSpecifics Void
- data JSONType
  - = TyObject
  - | TyArray
  - | TyString
  - | TyNumber
  - | TyBool
  - | TyNull
- displayJSONType :: JSONType -> Text
- displayError :: (err -> Text) -> ParseError err -> [Text]
- displayError' :: ParseError' -> [Text]
- displayPath :: [PathPiece] -> Text
- displaySpecifics :: (err -> Text) -> ErrorSpecifics err -> [Text]
- displaySpecifics' :: ErrorSpecifics' -> [Text]
- jsonTypeOf :: Value -> JSONType
- liftParseT :: forall (m :: Type -> Type) err a. (Functor m, Monad m) => (Value -> ExceptT (ErrorSpecifics err) m a) -> ParseT err m a
- liftParseM :: (Functor m, Monad m) => (Value -> m (Either (ErrorSpecifics err) a)) -> ParseT err m a
- liftParse :: forall (m :: Type -> Type) err a. (Functor m, Monad m) => (Value -> Either (ErrorSpecifics err) a) -> ParseT err m a
- badSchema :: forall (m :: Type -> Type) err a. (Functor m, Monad m) => ErrorSpecifics err -> ParseT err m a
- as :: forall (m :: Type -> Type) a err. (Functor m, Monad m) => (Value -> Maybe a) -> JSONType -> ParseT err m a
- asValue :: forall (m :: Type -> Type) err. (Functor m, Monad m) => ParseT err m Value
- asText :: forall (m :: Type -> Type) err. (Functor m, Monad m) => ParseT err m Text
- asString :: forall (m :: Type -> Type) err. (Functor m, Monad m) => ParseT err m String
- asScientific :: forall (m :: Type -> Type) err. (Functor m, Monad m) => ParseT err m Scientific
- asIntegral :: forall (m :: Type -> Type) a err. (Functor m, Monad m, Integral a) => ParseT err m a
- asRealFloat :: forall (m :: Type -> Type) a err. (Functor m, Monad m, RealFloat a) => ParseT err m a
- asBool :: forall (m :: Type -> Type) err. (Functor m, Monad m) => ParseT err m Bool
- asObject :: forall (m :: Type -> Type) err. (Functor m, Monad m) => ParseT err m Object
- asArray :: forall (m :: Type -> Type) err. (Functor m, Monad m) => ParseT err m Array
- asNull :: forall (m :: Type -> Type) err. (Functor m, Monad m) => ParseT err m ()
- perhaps :: forall (m :: Type -> Type) err a. (Functor m, Monad m) => ParseT err m a -> ParseT err m (Maybe a)
- key :: forall (m :: Type -> Type) err a. (Functor m, Monad m) => Text -> ParseT err m a -> ParseT err m a
- keyOrDefault :: forall (m :: Type -> Type) a err. (Functor m, Monad m) => Text -> a -> ParseT err m a -> ParseT err m a
- keyMay :: forall (m :: Type -> Type) err a. (Functor m, Monad m) => Text -> ParseT err m a -> ParseT err m (Maybe a)
- key' :: forall (m :: Type -> Type) err a. (Functor m, Monad m) => ParseT err m a -> Text -> ParseT err m a -> ParseT err m a
- nth :: forall (m :: Type -> Type) err a. (Functor m, Monad m) => Int -> ParseT err m a -> ParseT err m a
- nthOrDefault :: forall (m :: Type -> Type) a err. (Functor m, Monad m) => Int -> a -> ParseT err m a -> ParseT err m a
- nthMay :: forall (m :: Type -> Type) err a. (Functor m, Monad m) => Int -> ParseT err m a -> ParseT err m (Maybe a)
- nth' :: forall (m :: Type -> Type) err a. (Functor m, Monad m) => ParseT err m a -> Int -> ParseT err m a -> ParseT err m a
- eachInArray :: forall (m :: Type -> Type) err a. (Functor m, Monad m) => ParseT err m a -> ParseT err m [a]
- forEachInObject :: forall (m :: Type -> Type) err a. (Functor m, Monad m) => (Text -> ParseT err m a) -> ParseT err m [a]
- eachInObject :: forall (m :: Type -> Type) err a. (Functor m, Monad m) => ParseT err m a -> ParseT err m [(Text, a)]
- eachInObjectWithKey :: forall (m :: Type -> Type) err k a. (Functor m, Monad m) => (Text -> Either err k) -> ParseT err m a -> ParseT err m [(k, a)]
- withValue :: forall (m :: Type -> Type) err a. (Functor m, Monad m) => (Value -> Either err a) -> ParseT err m a
- withValueM :: (Functor m, Monad m) => (Value -> m (Either err a)) -> ParseT err m a
- liftEither :: forall (m :: Type -> Type) err a. (Functor m, Monad m) => Either err a -> ParseT err m a
- withM :: (Functor m, Monad m) => ParseT err m a -> (a -> m (Either err b)) -> ParseT err m b
- with :: forall (m :: Type -> Type) err a b. (Functor m, Monad m) => ParseT err m a -> (a -> Either err b) -> ParseT err m b
- withTextM :: (Functor m, Monad m) => (Text -> m (Either err a)) -> ParseT err m a
- withText :: forall (m :: Type -> Type) err a. (Functor m, Monad m) => (Text -> Either err a) -> ParseT err m a
- withStringM :: (Functor m, Monad m) => (String -> m (Either err a)) -> ParseT err m a
- withString :: forall (m :: Type -> Type) err a. (Functor m, Monad m) => (String -> Either err a) -> ParseT err m a
- withScientificM :: (Functor m, Monad m) => (Scientific -> m (Either err a)) -> ParseT err m a
- withScientific :: forall (m :: Type -> Type) err a. (Functor m, Monad m) => (Scientific -> Either err a) -> ParseT err m a
- withIntegralM :: (Functor m, Monad m, Integral a) => (a -> m (Either err b)) -> ParseT err m b
- withIntegral :: forall (m :: Type -> Type) a err b. (Functor m, Monad m, Integral a) => (a -> Either err b) -> ParseT err m b
- withRealFloatM :: (Functor m, Monad m, RealFloat a) => (a -> m (Either err b)) -> ParseT err m b
- withRealFloat :: forall (m :: Type -> Type) a err b. (Functor m, Monad m, RealFloat a) => (a -> Either err b) -> ParseT err m b
- withBoolM :: (Functor m, Monad m) => (Bool -> m (Either err a)) -> ParseT err m a
- withBool :: forall (m :: Type -> Type) err a. (Functor m, Monad m) => (Bool -> Either err a) -> ParseT err m a
- withObjectM :: (Functor m, Monad m) => (Object -> m (Either err a)) -> ParseT err m a
- withObject :: forall (m :: Type -> Type) err a. (Functor m, Monad m) => (Object -> Either err a) -> ParseT err m a
- withArrayM :: (Functor m, Monad m) => (Array -> m (Either err a)) -> ParseT err m a
- withArray :: forall (m :: Type -> Type) err a. (Functor m, Monad m) => (Array -> Either err a) -> ParseT err m a
- throwCustomError :: forall (m :: Type -> Type) err a. (Functor m, Monad m) => err -> ParseT err m a
- liftCustomT :: forall (m :: Type -> Type) err a. (Functor m, Monad m) => ExceptT err m a -> ParseT err m a

# Documentation

newtype ParseT err (m :: Type -> Type) a #

The type of parsers: things which consume JSON values and produce either detailed errors or successfully parsed values (of other types).

The `err` type parameter is for custom validation errors; for parsers that don't produce any custom validation errors, I recommend you just stick a type variable in for full generality:

        asTuple :: Parse e (Int, Int)
        asTuple = (,) <$> nth 0 asIntegral <*> nth 1 asIntegral

The `m` parameter allows you to run the parser within an abitrary underlying Monad. You may want to use `Parse` in most cases instead, and all functions in this module work on either.

Constructors

ParseT (ReaderT ParseReader (ExceptT (ParseError err) m) a) |

#### Instances

Instances details

Monad m => MonadReader ParseReader (ParseT err m) # |
Instance details Defined in Data.Aeson.BetterErrors.Internal Methods ask :: ParseT err m ParseReader # local :: (ParseReader -> ParseReader) -> ParseT err m a -> ParseT err m a # reader :: (ParseReader -> a) -> ParseT err m a #
MonadTrans (ParseT err) # |
Instance details Defined in Data.Aeson.BetterErrors.Internal Methods lift :: Monad m => m a -> ParseT err m a #
Monad m => MonadError (ParseError err) (ParseT err m) # |
Instance details Defined in Data.Aeson.BetterErrors.Internal Methods throwError :: ParseError err -> ParseT err m a # catchError :: ParseT err m a -> (ParseError err -> ParseT err m a) -> ParseT err m a #
Monad m => Applicative (ParseT err m) # |
Instance details Defined in Data.Aeson.BetterErrors.Internal Methods pure :: a -> ParseT err m a # (<*>) :: ParseT err m (a -> b) -> ParseT err m a -> ParseT err m b # liftA2 :: (a -> b -> c) -> ParseT err m a -> ParseT err m b -> ParseT err m c # (*>) :: ParseT err m a -> ParseT err m b -> ParseT err m b # (<*) :: ParseT err m a -> ParseT err m b -> ParseT err m a #
Functor m => Functor (ParseT err m) # |
Instance details Defined in Data.Aeson.BetterErrors.Internal Methods fmap :: (a -> b) -> ParseT err m a -> ParseT err m b # (<$) :: a -> ParseT err m b -> ParseT err m a #
Monad m => Monad (ParseT err m) # |
Instance details Defined in Data.Aeson.BetterErrors.Internal Methods (>>=) :: ParseT err m a -> (a -> ParseT err m b) -> ParseT err m b # (>>) :: ParseT err m a -> ParseT err m b -> ParseT err m b # return :: a -> ParseT err m a #

type Parse err a = ParseT err Identity a #

This is the standard version of `ParseT` over the `Identity` Monad, for running pure parsers.

runParseT :: ParseT err m a -> Value -> m (Either (ParseError err) a) #

runParse :: Parse err a -> Value -> Either (ParseError err) a #

mapParseT :: forall err (m :: Type -> Type) a err' (m' :: Type -> Type) a'. (ReaderT ParseReader (ExceptT (ParseError err) m) a -> ReaderT ParseReader (ExceptT (ParseError err') m') a') -> ParseT err m a -> ParseT err' m' a' #

mapError :: forall (m :: Type -> Type) err err' a. Functor m => (err -> err') -> ParseT err m a -> ParseT err' m a #

Transform the error of a parser according to the given function.

(.!) :: forall (m :: Type -> Type) err a err'. Functor m => ParseT err m a -> (err -> err') -> ParseT err' m a #

An infix version of `mapError`.

(<|>) :: forall (m :: Type -> Type) err a. Monad m => ParseT err m a -> ParseT err m a -> ParseT err m a infixl 3 #

First try the left parser, if that fails try the right. | If both fail, the error will come from the right one.

type Parse' a = Parse Void a #

The type of parsers which never produce custom validation errors.

runParserT :: Monad m => (s -> Either String Value) -> ParseT err m a -> s -> m (Either (ParseError err) a) #

runParser :: (s -> Either String Value) -> Parse err a -> s -> Either (ParseError err) a #

parseM :: Monad m => ParseT err m a -> ByteString -> m (Either (ParseError err) a) #

Like `parse` but runs the parser on an arbitrary underlying Monad.

parse :: Parse err a -> ByteString -> Either (ParseError err) a #

Run a parser with a lazy `ByteString` containing JSON data. Note that the normal caveat applies: the JSON supplied must contain either an object or an array for this to work.

parseStrictM :: Monad m => ParseT err m a -> ByteString -> m (Either (ParseError err) a) #

Like `parseStrict` but runs the parser on an arbitrary underlying Monad.

parseStrict :: Parse err a -> ByteString -> Either (ParseError err) a #

Run a parser with a strict `ByteString` containing JSON data. Note that the normal caveat applies: the JSON supplied must contain either an object or an array for this to work.

parseValueM :: Monad m => ParseT err m a -> Value -> m (Either (ParseError err) a) #

Like `parseValue` but runs the parser on an arbitrary underlying Monad.

parseValue :: Parse err a -> Value -> Either (ParseError err) a #

Run a parser with a pre-parsed JSON `Value`.

toAesonParser :: (err -> Text) -> Parse err a -> Value -> Parser a #

This function is useful when you have a ``Parse` err a` and you want to obtain an instance for ``FromJSON` a`. Simply define:

       parseJSON = toAesonParser showMyCustomError myParser

toAesonParser' :: Parse' a -> Value -> Parser a #

Take a parser which never produces custom validation errors and turn it into an Aeson parser. Note that in this case, there is no need to provide a display function.

fromAesonParser :: forall (m :: Type -> Type) a e. (Functor m, Monad m, FromJSON a) => ParseT e m a #

Create a parser for any type, using its FromJSON instance. Generally, you should prefer to write parsers using the other functions in this module; `key`, `asString`, etc, since they will usually generate better error messages. However this function is also useful occasionally.

data ParseReader #

Data used internally by the `Parse` type.

Constructors

ParseReader |
Fields rdrPath :: DList PathPiece rdrValue :: Value

#### Instances

Instances details

Monad m => MonadReader ParseReader (ParseT err m) # |
Instance details Defined in Data.Aeson.BetterErrors.Internal Methods ask :: ParseT err m ParseReader # local :: (ParseReader -> ParseReader) -> ParseT err m a -> ParseT err m a # reader :: (ParseReader -> a) -> ParseT err m a #

appendPath :: PathPiece -> ParseReader -> ParseReader #

setValue :: Value -> ParseReader -> ParseReader #

data PathPiece #

A piece of a path leading to a specific part of the JSON data. Internally, a list of these is maintained as the parser traverses the JSON data. This list is included in the error if one occurs.

Constructors

ObjectKey Text |
ArrayIndex Int |

#### Instances

Instances details

Show PathPiece # |
Instance details Defined in Data.Aeson.BetterErrors.Internal Methods showsPrec :: Int -> PathPiece -> ShowS # show :: PathPiece -> String # showList :: [PathPiece] -> ShowS #
Eq PathPiece # |
Instance details Defined in Data.Aeson.BetterErrors.Internal Methods (==) :: PathPiece -> PathPiece -> Bool # (/=) :: PathPiece -> PathPiece -> Bool #
Ord PathPiece # |
Instance details Defined in Data.Aeson.BetterErrors.Internal Methods compare :: PathPiece -> PathPiece -> Ordering # (<) :: PathPiece -> PathPiece -> Bool # (<=) :: PathPiece -> PathPiece -> Bool # (>) :: PathPiece -> PathPiece -> Bool # (>=) :: PathPiece -> PathPiece -> Bool # max :: PathPiece -> PathPiece -> PathPiece # min :: PathPiece -> PathPiece -> PathPiece #

data ParseError err #

A value indicating that the JSON could not be decoded successfully.

Constructors

InvalidJSON String | Indicates a syntax error in the JSON string. Unfortunately, in this case, Aeson's errors are not very helpful.
BadSchema [PathPiece] (ErrorSpecifics err) | Indicates a decoding error; the input was parsed as JSON successfully, but a value of the required type could not be constructed, perhaps because of a missing key or type mismatch.

#### Instances

Instances details

Functor ParseError # |
Instance details Defined in Data.Aeson.BetterErrors.Internal Methods fmap :: (a -> b) -> ParseError a -> ParseError b # (<$) :: a -> ParseError b -> ParseError a #
Show err => Show (ParseError err) # |
Instance details Defined in Data.Aeson.BetterErrors.Internal Methods showsPrec :: Int -> ParseError err -> ShowS # show :: ParseError err -> String # showList :: [ParseError err] -> ShowS #
Eq err => Eq (ParseError err) # |
Instance details Defined in Data.Aeson.BetterErrors.Internal Methods (==) :: ParseError err -> ParseError err -> Bool # (/=) :: ParseError err -> ParseError err -> Bool #
Monad m => MonadError (ParseError err) (ParseT err m) # |
Instance details Defined in Data.Aeson.BetterErrors.Internal Methods throwError :: ParseError err -> ParseT err m a # catchError :: ParseT err m a -> (ParseError err -> ParseT err m a) -> ParseT err m a #

type ParseError' = ParseError Void #

The type of parse errors which never involve custom validation errors.

data ErrorSpecifics err #

Detailed information in the case where a value could be parsed as JSON, but a value of the required type could not be constructed from it, for some reason.

Constructors

KeyMissing Text |
OutOfBounds Int |
WrongType JSONType Value | Expected type, actual value
ExpectedIntegral Double |
FromAeson String | An error arising inside a `FromJSON` instance.
CustomError err |

#### Instances

Instances details

Functor ErrorSpecifics # |
Instance details Defined in Data.Aeson.BetterErrors.Internal Methods fmap :: (a -> b) -> ErrorSpecifics a -> ErrorSpecifics b # (<$) :: a -> ErrorSpecifics b -> ErrorSpecifics a #
Show err => Show (ErrorSpecifics err) # |
Instance details Defined in Data.Aeson.BetterErrors.Internal Methods showsPrec :: Int -> ErrorSpecifics err -> ShowS # show :: ErrorSpecifics err -> String # showList :: [ErrorSpecifics err] -> ShowS #
Eq err => Eq (ErrorSpecifics err) # |
Instance details Defined in Data.Aeson.BetterErrors.Internal Methods (==) :: ErrorSpecifics err -> ErrorSpecifics err -> Bool # (/=) :: ErrorSpecifics err -> ErrorSpecifics err -> Bool #

type ErrorSpecifics' = ErrorSpecifics Void #

The type of error specifics which never involve custom validation errors.

data JSONType #

An enumeration of the different types that JSON values may take.

Constructors

TyObject |
TyArray |
TyString |
TyNumber |
TyBool |
TyNull |

#### Instances

Instances details

Bounded JSONType # |
Instance details Defined in Data.Aeson.BetterErrors.Internal Methods minBound :: JSONType # maxBound :: JSONType #
Enum JSONType # |
Instance details Defined in Data.Aeson.BetterErrors.Internal Methods succ :: JSONType -> JSONType # pred :: JSONType -> JSONType # toEnum :: Int -> JSONType # fromEnum :: JSONType -> Int # enumFrom :: JSONType -> [JSONType] # enumFromThen :: JSONType -> JSONType -> [JSONType] # enumFromTo :: JSONType -> JSONType -> [JSONType] # enumFromThenTo :: JSONType -> JSONType -> JSONType -> [JSONType] #
Show JSONType # |
Instance details Defined in Data.Aeson.BetterErrors.Internal Methods showsPrec :: Int -> JSONType -> ShowS # show :: JSONType -> String # showList :: [JSONType] -> ShowS #
Eq JSONType # |
Instance details Defined in Data.Aeson.BetterErrors.Internal Methods (==) :: JSONType -> JSONType -> Bool # (/=) :: JSONType -> JSONType -> Bool #
Ord JSONType # |
Instance details Defined in Data.Aeson.BetterErrors.Internal Methods compare :: JSONType -> JSONType -> Ordering # (<) :: JSONType -> JSONType -> Bool # (<=) :: JSONType -> JSONType -> Bool # (>) :: JSONType -> JSONType -> Bool # (>=) :: JSONType -> JSONType -> Bool # max :: JSONType -> JSONType -> JSONType # min :: JSONType -> JSONType -> JSONType #

displayJSONType :: JSONType -> Text #

displayError :: (err -> Text) -> ParseError err -> [Text] #

Turn a `ParseError` into a human-readable list of `Text` values. They will be in a sensible order. For example, you can feed the result to `mapM putStrLn`, or `unlines`.

displayError' :: ParseError' -> [Text] #

A version of `displayError` for parsers which do not produce custom validation errors.

displayPath :: [PathPiece] -> Text #

displaySpecifics :: (err -> Text) -> ErrorSpecifics err -> [Text] #

displaySpecifics' :: ErrorSpecifics' -> [Text] #

A version of `displaySpecifics` for parsers which do not produce custom validation errors.

jsonTypeOf :: Value -> JSONType #

Get the type of a JSON value.

liftParseT :: forall (m :: Type -> Type) err a. (Functor m, Monad m) => (Value -> ExceptT (ErrorSpecifics err) m a) -> ParseT err m a #

liftParseM :: (Functor m, Monad m) => (Value -> m (Either (ErrorSpecifics err) a)) -> ParseT err m a #

liftParse :: forall (m :: Type -> Type) err a. (Functor m, Monad m) => (Value -> Either (ErrorSpecifics err) a) -> ParseT err m a #

Lift any parsing function into the `Parse` type.

badSchema :: forall (m :: Type -> Type) err a. (Functor m, Monad m) => ErrorSpecifics err -> ParseT err m a #

Aborts parsing, due to an error in the structure of the JSON - that is, any error other than the JSON not actually being parseable into a `Value`.

as :: forall (m :: Type -> Type) a err. (Functor m, Monad m) => (Value -> Maybe a) -> JSONType -> ParseT err m a #

asValue :: forall (m :: Type -> Type) err. (Functor m, Monad m) => ParseT err m Value #

Return the current JSON `Value` as is. This does no error checking and thus always succeeds. You probably don't want this parser unless the JSON at the current part of your structure is truly arbitrary. You should prefer to use more specific parsers, like `asText` or `asIntegral`, where possible.

asText :: forall (m :: Type -> Type) err. (Functor m, Monad m) => ParseT err m Text #

Parse a single JSON string as `Text`.

asString :: forall (m :: Type -> Type) err. (Functor m, Monad m) => ParseT err m String #

Parse a single JSON string as a `String`.

asScientific :: forall (m :: Type -> Type) err. (Functor m, Monad m) => ParseT err m Scientific #

Parse a single JSON number as a `Scientific`.

asIntegral :: forall (m :: Type -> Type) a err. (Functor m, Monad m, Integral a) => ParseT err m a #

Parse a single JSON number as any `Integral` type.

asRealFloat :: forall (m :: Type -> Type) a err. (Functor m, Monad m, RealFloat a) => ParseT err m a #

Parse a single JSON number as any `RealFloat` type.

asBool :: forall (m :: Type -> Type) err. (Functor m, Monad m) => ParseT err m Bool #

Parse a single JSON boolean as a `Bool`.

asObject :: forall (m :: Type -> Type) err. (Functor m, Monad m) => ParseT err m Object #

Parse a JSON object, as an `Object`. You should prefer functions like `eachInObject` where possible, since they will usually generate better error messages.

asArray :: forall (m :: Type -> Type) err. (Functor m, Monad m) => ParseT err m Array #

Parse a JSON array, as an `Array`. You should prefer functions like `eachInArray` where possible, since they will usually generate better error messages.

asNull :: forall (m :: Type -> Type) err. (Functor m, Monad m) => ParseT err m () #

Parse a single JSON null value. Useful if you want to throw an error in the case where something is not null.

perhaps :: forall (m :: Type -> Type) err a. (Functor m, Monad m) => ParseT err m a -> ParseT err m (Maybe a) #

Given a parser, transform it into a parser which returns `Nothing` when supplied with a JSON `null`, and otherwise, attempts to parse with the original parser; if this succeeds, the result becomes a `Just` value.

key :: forall (m :: Type -> Type) err a. (Functor m, Monad m) => Text -> ParseT err m a -> ParseT err m a #

Take the value corresponding to a given key in the current object.

keyOrDefault :: forall (m :: Type -> Type) a err. (Functor m, Monad m) => Text -> a -> ParseT err m a -> ParseT err m a #

Take the value corresponding to a given key in the current object, or if no property exists with that key, use the supplied default.

keyMay :: forall (m :: Type -> Type) err a. (Functor m, Monad m) => Text -> ParseT err m a -> ParseT err m (Maybe a) #

Take the value corresponding to a given key in the current object, or if no property exists with that key, return Nothing .

key' :: forall (m :: Type -> Type) err a. (Functor m, Monad m) => ParseT err m a -> Text -> ParseT err m a -> ParseT err m a #

nth :: forall (m :: Type -> Type) err a. (Functor m, Monad m) => Int -> ParseT err m a -> ParseT err m a #

Take the nth value of the current array.

nthOrDefault :: forall (m :: Type -> Type) a err. (Functor m, Monad m) => Int -> a -> ParseT err m a -> ParseT err m a #

Take the nth value of the current array, or if no value exists with that index, use the supplied default.

nthMay :: forall (m :: Type -> Type) err a. (Functor m, Monad m) => Int -> ParseT err m a -> ParseT err m (Maybe a) #

Take the nth value of the current array, or if no value exists with that index, return Nothing.

nth' :: forall (m :: Type -> Type) err a. (Functor m, Monad m) => ParseT err m a -> Int -> ParseT err m a -> ParseT err m a #

eachInArray :: forall (m :: Type -> Type) err a. (Functor m, Monad m) => ParseT err m a -> ParseT err m [a] #

Attempt to parse each value in the array with the given parser, and collect the results.

forEachInObject :: forall (m :: Type -> Type) err a. (Functor m, Monad m) => (Text -> ParseT err m a) -> ParseT err m [a] #

Parse each property in an object with the given parser, given the key as an argument, and collect the results.

eachInObject :: forall (m :: Type -> Type) err a. (Functor m, Monad m) => ParseT err m a -> ParseT err m [(Text, a)] #

Attempt to parse each property value in the object with the given parser, and collect the results.

eachInObjectWithKey :: forall (m :: Type -> Type) err k a. (Functor m, Monad m) => (Text -> Either err k) -> ParseT err m a -> ParseT err m [(k, a)] #

Attempt to parse each property in the object: parse the key with the given validation function, parse the value with the given parser, and collect the results.

withValue :: forall (m :: Type -> Type) err a. (Functor m, Monad m) => (Value -> Either err a) -> ParseT err m a #

Lifts a function attempting to validate an arbitrary JSON value into a parser. You should only use this if absolutely necessary; the other functions in this module will generally give better error reporting.

withValueM :: (Functor m, Monad m) => (Value -> m (Either err a)) -> ParseT err m a #

liftEither :: forall (m :: Type -> Type) err a. (Functor m, Monad m) => Either err a -> ParseT err m a #

withM :: (Functor m, Monad m) => ParseT err m a -> (a -> m (Either err b)) -> ParseT err m b #

with :: forall (m :: Type -> Type) err a b. (Functor m, Monad m) => ParseT err m a -> (a -> Either err b) -> ParseT err m b #

withTextM :: (Functor m, Monad m) => (Text -> m (Either err a)) -> ParseT err m a #

withText :: forall (m :: Type -> Type) err a. (Functor m, Monad m) => (Text -> Either err a) -> ParseT err m a #

withStringM :: (Functor m, Monad m) => (String -> m (Either err a)) -> ParseT err m a #

withString :: forall (m :: Type -> Type) err a. (Functor m, Monad m) => (String -> Either err a) -> ParseT err m a #

withScientificM :: (Functor m, Monad m) => (Scientific -> m (Either err a)) -> ParseT err m a #

withScientific :: forall (m :: Type -> Type) err a. (Functor m, Monad m) => (Scientific -> Either err a) -> ParseT err m a #

withIntegralM :: (Functor m, Monad m, Integral a) => (a -> m (Either err b)) -> ParseT err m b #

withIntegral :: forall (m :: Type -> Type) a err b. (Functor m, Monad m, Integral a) => (a -> Either err b) -> ParseT err m b #

withRealFloatM :: (Functor m, Monad m, RealFloat a) => (a -> m (Either err b)) -> ParseT err m b #

withRealFloat :: forall (m :: Type -> Type) a err b. (Functor m, Monad m, RealFloat a) => (a -> Either err b) -> ParseT err m b #

withBoolM :: (Functor m, Monad m) => (Bool -> m (Either err a)) -> ParseT err m a #

withBool :: forall (m :: Type -> Type) err a. (Functor m, Monad m) => (Bool -> Either err a) -> ParseT err m a #

withObjectM :: (Functor m, Monad m) => (Object -> m (Either err a)) -> ParseT err m a #

Prefer to use functions like `key` or `eachInObject` to this one where possible, as they will generate better error messages.

withObject :: forall (m :: Type -> Type) err a. (Functor m, Monad m) => (Object -> Either err a) -> ParseT err m a #

Prefer to use functions like `key` or `eachInObject` to this one where possible, as they will generate better error messages.

withArrayM :: (Functor m, Monad m) => (Array -> m (Either err a)) -> ParseT err m a #

Prefer to use functions like `nth` or `eachInArray` to this one where possible, as they will generate better error messages.

withArray :: forall (m :: Type -> Type) err a. (Functor m, Monad m) => (Array -> Either err a) -> ParseT err m a #

Prefer to use functions like `nth` or `eachInArray` to this one where possible, as they will generate better error messages.

throwCustomError :: forall (m :: Type -> Type) err a. (Functor m, Monad m) => err -> ParseT err m a #

Throw a custom validation error.

liftCustomT :: forall (m :: Type -> Type) err a. (Functor m, Monad m) => ExceptT err m a -> ParseT err m a #