Blame Data/Aeson/Parser.hs

Packit 9a2dfb
-- |
Packit 9a2dfb
-- Module:      Data.Aeson.Parser
Packit 9a2dfb
-- Copyright:   (c) 2012-2016 Bryan O'Sullivan
Packit 9a2dfb
--              (c) 2011 MailRank, Inc.
Packit 9a2dfb
-- License:     BSD3
Packit 9a2dfb
-- Maintainer:  Bryan O'Sullivan <bos@serpentine.com>
Packit 9a2dfb
-- Stability:   experimental
Packit 9a2dfb
-- Portability: portable
Packit 9a2dfb
--
Packit 9a2dfb
-- Efficiently and correctly parse a JSON string.  The string must be
Packit 9a2dfb
-- encoded as UTF-8.
Packit 9a2dfb
--
Packit 9a2dfb
-- It can be useful to think of parsing as occurring in two phases:
Packit 9a2dfb
--
Packit 9a2dfb
-- * Identification of the textual boundaries of a JSON value.  This
Packit 9a2dfb
--   is always strict, so that an invalid JSON document can be
Packit 9a2dfb
--   rejected as soon as possible.
Packit 9a2dfb
--
Packit 9a2dfb
-- * Conversion of a JSON value to a Haskell value.  This may be
Packit 9a2dfb
--   either immediate (strict) or deferred (lazy); see below for
Packit 9a2dfb
--   details.
Packit 9a2dfb
--
Packit 9a2dfb
-- The question of whether to choose a lazy or strict parser is
Packit 9a2dfb
-- subtle, but it can have significant performance implications,
Packit 9a2dfb
-- resulting in changes in CPU use and memory footprint of 30% to 50%,
Packit 9a2dfb
-- or occasionally more.  Measure the performance of your application
Packit 9a2dfb
-- with each!
Packit 9a2dfb
Packit 9a2dfb
module Data.Aeson.Parser
Packit 9a2dfb
    (
Packit 9a2dfb
    -- * Lazy parsers
Packit 9a2dfb
    -- $lazy
Packit 9a2dfb
      json
Packit 9a2dfb
    , value
Packit 9a2dfb
    , jstring
Packit 9a2dfb
    , scientific
Packit 9a2dfb
    -- * Strict parsers
Packit 9a2dfb
    -- $strict
Packit 9a2dfb
    , json'
Packit 9a2dfb
    , value'
Packit 9a2dfb
    -- * Decoding without FromJSON instances
Packit 9a2dfb
    , decodeWith
Packit 9a2dfb
    , decodeStrictWith
Packit 9a2dfb
    , eitherDecodeWith
Packit 9a2dfb
    , eitherDecodeStrictWith
Packit 9a2dfb
    ) where
Packit 9a2dfb
Packit 9a2dfb
import Prelude ()
Packit 9a2dfb
Packit 9a2dfb
import Data.Aeson.Parser.Internal (decodeStrictWith, decodeWith, eitherDecodeStrictWith, eitherDecodeWith, json, json', jstring, scientific, value, value')
Packit 9a2dfb
Packit 9a2dfb
-- $lazy
Packit 9a2dfb
--
Packit 9a2dfb
-- The 'json' and 'value' parsers decouple identification from
Packit 9a2dfb
-- conversion.  Identification occurs immediately (so that an invalid
Packit 9a2dfb
-- JSON document can be rejected as early as possible), but conversion
Packit 9a2dfb
-- to a Haskell value is deferred until that value is needed.
Packit 9a2dfb
--
Packit 9a2dfb
-- This decoupling can be time-efficient if only a smallish subset of
Packit 9a2dfb
-- elements in a JSON value need to be inspected, since the cost of
Packit 9a2dfb
-- conversion is zero for uninspected elements.  The trade off is an
Packit 9a2dfb
-- increase in memory usage, due to allocation of thunks for values
Packit 9a2dfb
-- that have not yet been converted.
Packit 9a2dfb
Packit 9a2dfb
-- $strict
Packit 9a2dfb
--
Packit 9a2dfb
-- The 'json'' and 'value'' parsers combine identification with
Packit 9a2dfb
-- conversion.  They consume more CPU cycles up front, but have a
Packit 9a2dfb
-- smaller memory footprint.