-- Hoogle documentation, generated by Haddock -- See Hoogle, http://www.haskell.org/hoogle/ -- | Incremental applicative JSON parser -- -- Easy to use JSON parser fully supporting incremental parsing. Parsing -- grammar in applicative form. -- -- The parser is compatibile with aeson and its FromJSON class. It is -- possible to use aeson monadic parsing when appropriate. -- -- The parser supports constant-space safe incremental parsing regardless -- of the input data. In addition to performance-critical parts written -- in C, a lot of performance is gained by being less memory intensive -- especially when used for stream parsing. -- --
-- >>> parseByteString (arrayOf integer) "[1,2,3,4]" :: [Int] -- [1,2,3,4] ---- --
-- >>> parseByteString (arrayOf ("name" .: string)) "[{\"name\":\"KIWI\"}, {\"name\":\"BIRD\"}]"
-- ["KIWI","BIRD"]
--
parseByteString :: Parser a -> ByteString -> [a]
-- | Parse a lazy bytestring, generate lazy list of parsed values. If an
-- error occurs, throws an exception.
parseLazyByteString :: Parser a -> ByteString -> [a]
-- | Deserialize a JSON value from lazy ByteString.
--
-- If this fails due to incomplete or invalid input, Nothing is
-- returned.
--
-- The input must consist solely of a JSON document, with no trailing
-- data except for whitespace.
decode :: FromJSON a => ByteString -> Maybe a
-- | Like decode but returns an error message when decoding fails.
eitherDecode :: FromJSON a => ByteString -> Either String a
-- | Like decode, but on strict ByteString
decodeStrict :: FromJSON a => ByteString -> Maybe a
-- | Like eitherDecode, but on strict ByteString
eitherDecodeStrict :: FromJSON a => ByteString -> Either String a
-- | Match FromJSON value. Calls parseJSON on the parsed value.
--
--
-- >>> let json = "[{\"key1\": [1,2], \"key2\": [5,6]}]"
--
-- >>> parseByteString (arrayOf value) json :: [AE.Value]
-- [Object (fromList [("key2",Array [Number 5.0,Number 6.0]),("key1",Array [Number 1.0,Number 2.0])])]
--
value :: FromJSON a => Parser a
-- | Parse string value, skip parsing otherwise.
string :: Parser Text
-- | Stops parsing string after the limit is reached. The string will not
-- be matched if it exceeds the size. The size is the size of escaped
-- string including escape characters.
safeString :: Int -> Parser Text
-- | Parse number, return in scientific format.
number :: Parser Scientific
-- | Parse to bounded integer type (not Integer). If you are using
-- integer numbers, use this parser. It skips the conversion JSON ->
-- Scientific -> Int and uses an Int directly.
integer :: forall i. (Integral i, Bounded i) => Parser i
-- | Parse to float/double.
real :: RealFloat a => Parser a
-- | Parse bool, skip if the type is not bool.
bool :: Parser Bool
-- | Match a null value.
jNull :: Parser ()
-- | Synonym for objectWithKey. Matches key in an object. The
-- .: operators can be chained.
--
--
-- >>> let json = "{\"key1\": {\"nested-key\": 3}}"
--
-- >>> parseByteString ("key1" .: "nested-key" .: integer) json :: [Int]
-- [3]
--
(.:) :: Text -> Parser a -> Parser a
infixr 7 .:
-- | Returns Nothing if value is null or does not exist or match.
-- Otherwise returns Just value.
--
-- -- key .:? val = optional (key .: val) --(.:?) :: Text -> Parser a -> Parser (Maybe a) infixr 7 .:? -- | Return default value if the parsers on the left hand didn't produce a -- result. -- --
-- p .| defval = p <|> pure defval ---- -- The operator works on complete left side, the following statements are -- equal: -- --
-- Record <$> "key1" .: "nested-key" .: value .| defaultValue
-- Record <$> (("key1" .: "nested-key" .: value) .| defaultValue)
--
(.|) :: Parser a -> a -> Parser a
infixl 6 .|
-- | Synonym for arrayWithIndexOf. Matches n-th item in array.
--
-- -- >>> parseByteString (arrayOf (1 .! bool)) "[ [1,true,null], [2,false], [3]]" :: [Bool] -- [True,False] --(.!) :: Int -> Parser a -> Parser a infixr 7 .! -- | Match only specific key of an object. This function will return only -- the first matched value in an object even if the source JSON defines -- the key multiple times (in violation of the specification). objectWithKey :: Text -> Parser a -> Parser a -- | Match all key-value pairs of an object, return them as a tuple. If the -- source object defines same key multiple times, all values are matched. objectItems :: Parser a -> Parser (Text, a) -- | Match all key-value pairs of an object, return only values. If the -- source object defines same key multiple times, all values are matched. -- Keys are ignored. objectValues :: Parser a -> Parser a -- | Match all items of an array. arrayOf :: Parser a -> Parser a -- | Match nith item in an array. arrayWithIndexOf :: Int -> Parser a -> Parser a -- | Match all items of an array, add index to output. indexedArrayOf :: Parser a -> Parser (Int, a) -- | Parses a field with a possible null value. nullable :: Parser a -> Parser (Maybe a) -- | Let only items matching a condition pass. -- --
-- >>> parseByteString (filterI (>5) $ arrayOf integer) "[1,2,3,4,5,6,7,8,9,0]" :: [Int] -- [6,7,8,9] --filterI :: (a -> Bool) -> Parser a -> Parser a -- | Take maximum n matching items. -- --
-- >>> parseByteString (takeI 3 $ arrayOf integer) "[1,2,3,4,5,6,7,8,9,0]" :: [Int] -- [1,2,3] --takeI :: Int -> Parser a -> Parser a -- | A back-door for lifting of possibly failing actions. If an action -- fails with Left value, convert it into failure of parsing mapWithFailure :: (a -> Either String b) -> Parser a -> Parser b -- | Generate start/end values when an array is found, in between run a -- parser. The inner parser is not run if an array is not found. -- --
-- >>> let test = "[[1,2,3],true,[],false,{\"key\":1}]" :: BS.ByteString
--
-- >>> parseByteString (arrayOf (arrayFound 10 20 (1 .! integer))) test :: [Int]
-- [10,2,20,10,20]
--
arrayFound :: a -> a -> Parser a -> Parser a
-- | Generate start/end values when an object is found, in between run a
-- parser. The inner parser is not run if an array is not found.
objectFound :: a -> a -> Parser a -> Parser a
instance GHC.Base.Functor Data.JsonStream.Parser.ParseResult
instance GHC.Base.Functor Data.JsonStream.Parser.Parser
instance GHC.Base.Applicative Data.JsonStream.Parser.Parser
instance GHC.Base.Monoid (Data.JsonStream.Parser.Parser a)
instance Data.Semigroup.Semigroup (Data.JsonStream.Parser.Parser a)
instance GHC.Base.Alternative Data.JsonStream.Parser.Parser