HORIZON HASKELLDocslts/ghc-9.10.xc74966e2026-09-27Search names, modules, packages, or :: a typeCtrl K

GHC 9.10.3 · lts/ghc-9.10.x · c74966e · 2026-09-27

Moduleattoparsec-aeson-2.2.2.0Haskell2010

Data.Aeson.Parser.Internal

Efficiently and correctly parse a JSON string. The string must be encoded as UTF-8.

  • 24 values

Lazy parsers

10 declarations
valuejson :: Parser Value
#

Parse any JSON value.

The conversion of a parsed value to a Haskell value is deferred until the Haskell value is needed. This may improve performance if only a subset of the results of conversions are needed, but at a cost in thunk allocation.

This function is an alias for value. In aeson 0.8 and earlier, it parsed only object or array types, in conformance with the now-obsolete RFC 4627.

Warning

If an object contains duplicate keys, only the first one will be kept. For a more flexible alternative, see jsonWith.

valuejsonEOF :: Parser Value
#

Parse a top-level JSON value followed by optional whitespace and end-of-input. See also: json.

valuejsonWith :: ([(Key, Value)] -> Either String Object) -> Parser Value
#

Parse any JSON value.

This parser is parameterized by a function to construct an Object from a raw list of key-value pairs, where duplicates are preserved. The pairs appear in reverse order from the source.

Examples

json keeps only the first occurrence of each key, using fromList.

json = jsonWith (Right . H.fromList)

jsonLast keeps the last occurrence of each key, using HashMap.Lazy.fromListWith (const id).

jsonLast = jsonWith (Right . HashMap.Lazy.fromListWith (const id))

jsonAccum keeps wraps all values in arrays to keep duplicates, using fromListAccum.

jsonAccum = jsonWith (Right . fromListAccum)

jsonNoDup fails if any object contains duplicate keys, using parseListNoDup.

jsonNoDup = jsonWith parseListNoDup

Strict parsers

7 declarations
valuejson' :: Parser Value
#

Parse any JSON value.

This is a strict version of json which avoids building up thunks during parsing; it performs all conversions immediately. Prefer this version if most of the JSON data needs to be accessed.

This function is an alias for value'. In aeson 0.8 and earlier, it parsed only object or array types, in conformance with the now-obsolete RFC 4627.

Warning

If an object contains duplicate keys, only the first one will be kept. For a more flexible alternative, see jsonWith'.

valuejsonEOF' :: Parser Value
#

Parse a top-level JSON value followed by optional whitespace and end-of-input. See also: json'.

Helpers

4 declarations

Handling objects with duplicate keys

valuefromListAccum :: [(Key, Value)] -> Object
#

fromListAccum kvs is an object mapping keys to arrays containing all associated values from the original list kvs.

Example1 expression
fromListAccum [("apple", Bool True), ("apple", Bool False), ("orange", Bool False)]fromList [("apple",Array [Bool False,Bool True]),("orange",Array [Bool False])]

Text literal unescaping

1 declaration