aeson-0.11.2.1: Fast JSON parsing and encoding

Copyright(c) 2015-2016 Bryan O'Sullivan
LicenseBSD3
MaintainerBryan O'Sullivan <bos@serpentine.com>
Stabilityexperimental
Portabilityportable
Safe HaskellNone
LanguageHaskell2010

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

Documentation

data JSONPathElement Source

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

Constructors

Key Text

JSON path element of a key into an object, "object.key".

Index !Int

JSON path element of an index into an array, "array[index]".

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

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 Source

Annotate an error message with a JSONPath error location.

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

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

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

Run a Parser.