Data.Aeson.Internal

aeson-2.1.0.0: Fast JSON parsing and encoding

Copyright | (c) 2015-2016 Bryan O'Sullivan
License | BSD3
Maintainer | Bryan O'Sullivan <bos@serpentine.com>
Stability | experimental
Portability | portable
Safe Haskell | Safe-Inferred
Language | Haskell2010

Data.Aeson.Internal

Description

Internal types and functions.

Note: all declarations in this module are unstable, and prone to being changed at any time.

Synopsis

- data IResult a
  - = IError JSONPath String
  - | ISuccess a
- data JSONPathElement
  - = Key Key
  - | Index !Int
- type JSONPath = [JSONPathElement]
- (<?>) :: Parser a -> JSONPathElement -> Parser a
- formatError :: JSONPath -> String -> String
- ifromJSON :: FromJSON a => Value -> IResult a
- iparse :: (a -> Parser b) -> a -> IResult b

# Documentation

data IResult a #

The internal result of running a `Parser`.

Constructors

IError JSONPath String |
ISuccess a |

#### Instances

Instances details

MonadFail IResult # |
Instance details Defined in Data.Aeson.Types.Internal Methods fail :: String -> IResult a #
Foldable IResult # |
Instance details Defined in Data.Aeson.Types.Internal Methods fold :: Monoid m => IResult m -> m # foldMap :: Monoid m => (a -> m) -> IResult a -> m # foldMap' :: Monoid m => (a -> m) -> IResult a -> m # foldr :: (a -> b -> b) -> b -> IResult a -> b # foldr' :: (a -> b -> b) -> b -> IResult a -> b # foldl :: (b -> a -> b) -> b -> IResult a -> b # foldl' :: (b -> a -> b) -> b -> IResult a -> b # foldr1 :: (a -> a -> a) -> IResult a -> a # foldl1 :: (a -> a -> a) -> IResult a -> a # toList :: IResult a -> [a] # null :: IResult a -> Bool # length :: IResult a -> Int # elem :: Eq a => a -> IResult a -> Bool # maximum :: Ord a => IResult a -> a # minimum :: Ord a => IResult a -> a # sum :: Num a => IResult a -> a # product :: Num a => IResult a -> a #
Traversable IResult # |
Instance details Defined in Data.Aeson.Types.Internal Methods traverse :: Applicative f => (a -> f b) -> IResult a -> f (IResult b) # sequenceA :: Applicative f => IResult (f a) -> f (IResult a) # mapM :: Monad m => (a -> m b) -> IResult a -> m (IResult b) # sequence :: Monad m => IResult (m a) -> m (IResult a) #
Alternative IResult # |
Instance details Defined in Data.Aeson.Types.Internal Methods empty :: IResult a # (<|>) :: IResult a -> IResult a -> IResult a # some :: IResult a -> IResult [a] # many :: IResult a -> IResult [a] #
Applicative IResult # |
Instance details Defined in Data.Aeson.Types.Internal Methods pure :: a -> IResult a # (<*>) :: IResult (a -> b) -> IResult a -> IResult b # liftA2 :: (a -> b -> c) -> IResult a -> IResult b -> IResult c # (*>) :: IResult a -> IResult b -> IResult b # (<*) :: IResult a -> IResult b -> IResult a #
Functor IResult # |
Instance details Defined in Data.Aeson.Types.Internal Methods fmap :: (a -> b) -> IResult a -> IResult b # (<$) :: a -> IResult b -> IResult a #
Monad IResult # |
Instance details Defined in Data.Aeson.Types.Internal Methods (>>=) :: IResult a -> (a -> IResult b) -> IResult b # (>>) :: IResult a -> IResult b -> IResult b # return :: a -> IResult a #
MonadPlus IResult # |
Instance details Defined in Data.Aeson.Types.Internal Methods mzero :: IResult a # mplus :: IResult a -> IResult a -> IResult a #
Monoid (IResult a) # |
Instance details Defined in Data.Aeson.Types.Internal Methods mempty :: IResult a # mappend :: IResult a -> IResult a -> IResult a # mconcat :: [IResult a] -> IResult a #
Semigroup (IResult a) # |
Instance details Defined in Data.Aeson.Types.Internal Methods (<>) :: IResult a -> IResult a -> IResult a # sconcat :: NonEmpty (IResult a) -> IResult a # stimes :: Integral b => b -> IResult a -> IResult a #
Show a => Show (IResult a) # |
Instance details Defined in Data.Aeson.Types.Internal Methods showsPrec :: Int -> IResult a -> ShowS # show :: IResult a -> String # showList :: [IResult a] -> ShowS #
NFData a => NFData (IResult a) # |
Instance details Defined in Data.Aeson.Types.Internal Methods rnf :: IResult a -> () #
Eq a => Eq (IResult a) # |
Instance details Defined in Data.Aeson.Types.Internal Methods (==) :: IResult a -> IResult a -> Bool # (/=) :: IResult a -> IResult a -> Bool #

data JSONPathElement #

Elements of a JSON path used to describe the location of an error.

Constructors

Key Key | JSON path element of a key into an object, "object.key".
Index !Int | JSON path element of an index into an array, "array[index]".

#### Instances

Instances details

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

type JSONPath = [JSONPathElement] #

(<?>) :: Parser a -> JSONPathElement -> Parser a #

Add JSON Path context to a parser

When parsing a complex structure, it helps to annotate (sub)parsers with context, so that if an error occurs, you can find its location.

    withObject "Person" $ \o ->
      Person
        <$> o .: "name" <?> Key "name"
        <*> o .: "age"  <?> Key "age"

(Standard methods like `(.:)` already do this.)

With such annotations, if an error occurs, you will get a JSON Path location of that error.

Since 0.10

formatError :: JSONPath -> String -> String #

Annotate an error message with a JSONPath error location.

ifromJSON :: FromJSON a => Value -> IResult a #

Convert a value from JSON, failing if the types do not match.

iparse :: (a -> Parser b) -> a -> IResult b #

Run a `Parser`.