-- Hoogle documentation, generated by Haddock -- See Hoogle, http://www.haskell.org/hoogle/ -- | Dead simple JSON parser, with some Template Haskell sugar. -- -- This is dead simple JSON, consisting of a simple parser built with -- Parsec and some Template Haskell syntactic sugar (which you may or may -- not use, it works without). @package dead-simple-json @version 0.1.2 -- | The basic JSON data types. module Text.DeadSimpleJSON.Types -- | A JSON value. data Value -- | A JSON String, represented as ordinary Haskell String. String :: String -> Value -- | A JSON Number, represented by two Integers in exponontial form. -- Number n e is the same as {n}e{exp}, that is n * -- 10 ^ e. This allows for arbitrary precision fixed point -- rationals. See Convert for easy conversions. Number :: !Integer -> !Integer -> Value -- | A JSON Object, represented as Map. Object :: (Map String Value) -> Value -- | A JSON Array, represented as Vector of Values. Array :: (Vector Value) -> Value -- | True. True :: Value -- | False. False :: Value -- | Null (void, unit, ()). Null :: Value -- | A top-level JSON object. -- -- Merely a wrapper that ensures that no other Values but -- Array and Object reside at the top-level. newtype JSON JSON :: Value -> JSON instance Typeable Value instance Typeable JSON instance Eq Value instance Show Value instance Read Value instance Data Value instance Eq JSON instance Data JSON module Text.DeadSimpleJSON.Convert -- | A JSON value. data Value -- | A JSON String, represented as ordinary Haskell String. String :: String -> Value -- | A JSON Number, represented by two Integers in exponontial form. -- Number n e is the same as {n}e{exp}, that is n * -- 10 ^ e. This allows for arbitrary precision fixed point -- rationals. See Convert for easy conversions. Number :: !Integer -> !Integer -> Value -- | A JSON Object, represented as Map. Object :: (Map String Value) -> Value -- | A JSON Array, represented as Vector of Values. Array :: (Vector Value) -> Value -- | True. True :: Value -- | False. False :: Value -- | Null (void, unit, ()). Null :: Value class Convert a where convert' n@(Number _ _) = return $ convert n convert' _ = fail "" toJSON = undefined convert :: Convert a => Value -> a convert' :: Convert a => Value -> Maybe a toJSON :: Convert a => a -> Value instance [overlap ok] Convert Int64 instance [overlap ok] Convert Int32 instance [overlap ok] Convert Int16 instance [overlap ok] Convert Int8 instance [overlap ok] Convert Int instance [overlap ok] Convert Integer instance [overlap ok] (Read a, Integral a) => Convert (Ratio a) instance [overlap ok] Convert Float instance [overlap ok] Convert Double instance [overlap ok] Convert a => Convert [a] instance [overlap ok] Convert String instance [overlap ok] Convert Bool instance [overlap ok] Convert Value instance [overlap ok] Convert a => Convert (Maybe a) module Text.DeadSimpleJSON.Query query :: Convert a => Query -> JSON -> a query' :: Convert a => Query -> JSON -> Maybe a queryV :: Convert a => Query -> Value -> a queryV' :: Convert a => Query -> Value -> Maybe a data Query Field :: String -> Query -> Query Index :: Int -> Query -> Query Read :: Query mkQuery :: String -> Query mkQuery' :: String -> Either ParseError Query (?) :: Convert a => JSON -> String -> a instance Typeable Query instance Show Query instance Data Query -- | A simple approach for parsing JSON. -- -- To read JSON data use read. To print JSON data use show: -- --
-- let jsonData = read "[1,2,4,8,16]" :: JSON -- putStrLn $ show jsonData ---- -- You can query json data using ?. Querying implies conversion, -- therefor you may need to specify the result type: -- --
-- let jsonData = read "{\"seven\": 7, \"nine\": [1,2,4,8,16]}"
-- print $ (jsonData ? "nine[3]" :: Int)
--
--
-- For tighter control use parse. A more convenient way for
-- creating JSON objects in source code or querying JSON data, is using
-- Template Haskell. See Text.SimpleJSON.TH.
--
-- The recommended way for importing this module is importing it
-- qualified, like so:
--
-- -- import qualified Text.SimpleJSON as JSON -- import Text.SimpleJSON (JSON) --module Text.DeadSimpleJSON -- | Parse a String for JSON data or return a ParseError. parse :: String -> Either ParseError JSON -- | Parses a top-level JSON object, returning Just a Value or Nothing. parse' :: String -> Maybe Value -- | Purely Monadic version of parse'. parseM :: Monad m => String -> m Value -- | A JSON value. data Value -- | A JSON String, represented as ordinary Haskell String. String :: String -> Value -- | A JSON Number, represented by two Integers in exponontial form. -- Number n e is the same as {n}e{exp}, that is n * -- 10 ^ e. This allows for arbitrary precision fixed point -- rationals. See Convert for easy conversions. Number :: !Integer -> !Integer -> Value -- | A JSON Object, represented as Map. Object :: (Map String Value) -> Value -- | A JSON Array, represented as Vector of Values. Array :: (Vector Value) -> Value -- | True. True :: Value -- | False. False :: Value -- | Null (void, unit, ()). Null :: Value -- | A top-level JSON object. -- -- Merely a wrapper that ensures that no other Values but -- Array and Object reside at the top-level. data JSON (?) :: Convert a => JSON -> String -> a -- | Unwraps a top-level JSON object to a Value. top :: JSON -> Value class Convert a where convert' n@(Number _ _) = return $ convert n convert' _ = fail "" toJSON = undefined convert :: Convert a => Value -> a convert' :: Convert a => Value -> Maybe a toJSON :: Convert a => a -> Value instance Read JSON instance Show JSON -- | Template Haskell syntax sugar for working with JSON data. -- -- For using this module, you need to declare a LANGUAGE pragma like the -- following: -- --
-- {-# LANGUAGE Haskell2010, TemplateHaskell, QuasiQuotes #-}
--
module Text.DeadSimpleJSON.TH
-- | A QuasiQuoter which queries a json object using JavaScript notation.
--
-- Suppose obj contains a json object of type JSON:
--
-- -- [jsq| obj.prop.list[3] |] ---- -- The above will query the object in obj as if it was JavaScript. -- -- The type of the expression is polymorphic: Convert a => a. -- -- You will need to specify the type of the query, like so: -- --
-- [jsq| obj.prop.list |] :: [Integer] ---- -- For possible conversions, see the instances for Convert. jsq :: QuasiQuoter -- | A QuasiQuoter which includes JSON data. -- -- The type of the expression is JSON. json :: QuasiQuoter -- | A QuasiQuoter which includes JSON data from files. -- -- The following example will include the contents of data.json -- as JSON. -- --
-- let str = [jsonF|data.json|] ---- -- Note that every character inside the brackets is treated as part of -- the file name, that is [jsonF| data.json |] is not the same -- as the above example (it will try to find a file which name includes -- space characters). jsonF :: QuasiQuoter -- | A QuasiQuoter on raw strings. -- -- The definition is basically: -- --
-- s = QuasiQuoter {
-- quoteExp = return . LitE . StringL
-- }
--
s :: QuasiQuoter
-- | A QuasiQuoter which includes raw strings from files.
--
-- The following example will include the contents of file.txt
-- as a String.
--
-- -- let str = [sF|file.txt|] ---- -- Note that every character inside the brackets is treated as part of -- the file name, that is [sF| file.txt |] is not the same as -- the above example (it will try to find a file which name includes -- space characters). sF :: QuasiQuoter