-- Hoogle documentation, generated by Haddock -- See Hoogle, http://www.haskell.org/hoogle/ -- | Support for serialising Haskell to and from JSON -- -- JSON (JavaScript Object Notation) is a lightweight data-interchange -- format. It is easy for humans to read and write. It is easy for -- machines to parse and generate. It is based on a subset of the -- JavaScript Programming Language, Standard ECMA-262 3rd Edition - -- December 1999. -- -- This library provides a parser and pretty printer for converting -- between Haskell values and JSON. @package json @version 0.3.6 module Text.JSON.Types -- | JSON values -- -- The type to which we encode Haskell values. There's a set of -- primitives, and a couple of heterogenous collection types. -- -- Objects: -- -- An object structure is represented as a pair of curly brackets -- surrounding zero or more name/value pairs (or members). A name is a -- string. A single colon comes after each name, separating the name from -- the value. A single comma separates a value from a following name. -- -- Arrays: -- -- An array structure is represented as square brackets surrounding zero -- or more values (or elements). Elements are separated by commas. -- -- Only valid JSON can be constructed this way data JSValue JSNull :: JSValue JSBool :: !Bool -> JSValue JSRational :: !Rational -> JSValue JSString :: JSString -> JSValue JSArray :: [JSValue] -> JSValue JSObject :: (JSObject JSValue) -> JSValue -- | Strings can be represented a little more efficiently in JSON newtype JSString JSONString :: String -> JSString fromJSString :: JSString -> String -- | Turn a Haskell string into a JSON string. toJSString :: String -> JSString -- | As can association lists newtype JSObject e JSONObject :: [(String, e)] -> JSObject e fromJSObject :: JSObject e -> [(String, e)] -- | Make JSON object out of an association list. toJSObject :: [(String, a)] -> JSObject a -- | Get the value of a field, if it exist. get_field :: JSObject a -> String -> Maybe a -- | Set the value of a field. Previous values are overwritten. set_field :: JSObject a -> String -> a -> JSObject a instance Typeable1 JSObject instance Typeable JSString instance Typeable JSValue instance (Eq e) => Eq (JSObject e) instance (Ord e) => Ord (JSObject e) instance (Show e) => Show (JSObject e) instance (Read e) => Read (JSObject e) instance Eq JSString instance Ord JSString instance Show JSString instance Read JSString instance Show JSValue instance Read JSValue instance Eq JSValue instance Ord JSValue -- | Display JSON values using pretty printing combinators. module Text.JSON.Pretty pp_value :: JSValue -> Doc pp_null :: Doc pp_boolean :: Bool -> Doc pp_number :: Rational -> Doc pp_array :: [JSValue] -> Doc pp_string :: String -> Doc pp_object :: [(String, JSValue)] -> Doc pp_js_string :: JSString -> Doc pp_js_object :: JSObject JSValue -> Doc module Text.JSON.String -- | Parsing JSON -- -- The type of JSON parsers for String data GetJSON a -- | Run a JSON reader on an input String, returning some Haskell value. -- All input will be consumed. runGetJSON :: GetJSON a -> String -> Either String a -- | Read the JSON null type readJSNull :: GetJSON JSValue -- | Read the JSON Bool type readJSBool :: GetJSON JSValue -- | Read the JSON String type readJSString :: GetJSON JSValue -- | Read an Integer or Double in JSON format, returning a Rational readJSRational :: GetJSON Rational -- | Read a list in JSON format readJSArray :: GetJSON JSValue -- | Read an object in JSON format readJSObject :: GetJSON JSValue -- | Read one of several possible JS types readJSValue :: GetJSON JSValue -- | Top level JSON can only be Arrays or Objects readJSTopType :: GetJSON JSValue -- | Write the JSON null type showJSNull :: ShowS -- | Write the JSON Bool type showJSBool :: Bool -> ShowS -- | Show a Rational in JSON format showJSRational :: Rational -> ShowS -- | Show a list in JSON format showJSArray :: [JSValue] -> ShowS -- | Show an association list in JSON format showJSObject :: JSObject JSValue -> ShowS -- | Show JSON values showJSValue :: JSValue -> ShowS -- | Writing JSON -- -- Show strict JSON top level types. Values not permitted at the top -- level are wrapped in a singleton array. showJSTopType :: JSValue -> ShowS instance Monad GetJSON instance Functor GetJSON -- | Parse JSON values using the ReadP combinators. module Text.JSON.ReadP p_value :: ReadP JSValue p_null :: ReadP () p_boolean :: ReadP Bool p_array :: ReadP [JSValue] p_string :: ReadP String p_object :: ReadP [(String, JSValue)] p_number :: ReadP Rational p_js_string :: ReadP JSString p_js_object :: ReadP (JSObject JSValue) -- | Parse JSON values using the Parsec combinators. module Text.JSON.Parsec p_value :: CharParser () JSValue p_null :: CharParser () () p_boolean :: CharParser () Bool p_array :: CharParser () [JSValue] p_string :: CharParser () String p_object :: CharParser () [(String, JSValue)] p_number :: CharParser () Rational p_js_string :: CharParser () JSString p_js_object :: CharParser () (JSObject JSValue) module Text.JSON -- | JSON values -- -- The type to which we encode Haskell values. There's a set of -- primitives, and a couple of heterogenous collection types. -- -- Objects: -- -- An object structure is represented as a pair of curly brackets -- surrounding zero or more name/value pairs (or members). A name is a -- string. A single colon comes after each name, separating the name from -- the value. A single comma separates a value from a following name. -- -- Arrays: -- -- An array structure is represented as square brackets surrounding zero -- or more values (or elements). Elements are separated by commas. -- -- Only valid JSON can be constructed this way data JSValue JSNull :: JSValue JSBool :: !Bool -> JSValue JSRational :: !Rational -> JSValue JSString :: JSString -> JSValue JSArray :: [JSValue] -> JSValue JSObject :: (JSObject JSValue) -> JSValue -- | The class of types serialisable to and from JSON class JSON a readJSON :: (JSON a) => JSValue -> Result a showJSON :: (JSON a) => a -> JSValue readJSONs :: (JSON a) => JSValue -> Result [a] showJSONs :: (JSON a) => [a] -> JSValue -- | A type for parser results data Result a Ok :: a -> Result a Error :: String -> Result a -- | Encode a Haskell value into a string, in JSON format. -- -- This is a superset of JSON, as types other than Array and Object are -- allowed at the top level. encode :: (JSON a) => a -> String -- | Decode a String representing a JSON value (either an object, array, -- bool, number, null) -- -- This is a superset of JSON, as types other than Array and Object are -- allowed at the top level. decode :: (JSON a) => String -> Result a -- | Encode a value as a String in strict JSON format. This follows the -- spec, and requires all values at the top level to be wrapped in either -- an Array or Object. JSON types to be an Array or Object. encodeStrict :: (JSON a) => a -> String -- | Decode a String representing a strict JSON value. This follows the -- spec, and requires top level JSON types to be an Array or Object. decodeStrict :: (JSON a) => String -> Result a -- | Strings can be represented a little more efficiently in JSON data JSString -- | Turn a Haskell string into a JSON string. toJSString :: String -> JSString fromJSString :: JSString -> String -- | As can association lists data JSObject e -- | Make JSON object out of an association list. toJSObject :: [(String, a)] -> JSObject a fromJSObject :: JSObject e -> [(String, e)] -- | Map Results to Eithers resultToEither :: Result a -> Either String a -- | Read the JSON null type readJSNull :: GetJSON JSValue -- | Read the JSON Bool type readJSBool :: GetJSON JSValue -- | Read the JSON String type readJSString :: GetJSON JSValue -- | Read an Integer or Double in JSON format, returning a Rational readJSRational :: GetJSON Rational -- | Read a list in JSON format readJSArray :: GetJSON JSValue -- | Read an object in JSON format readJSObject :: GetJSON JSValue -- | Read one of several possible JS types readJSValue :: GetJSON JSValue -- | Write the JSON null type showJSNull :: ShowS -- | Write the JSON Bool type showJSBool :: Bool -> ShowS -- | Show a Rational in JSON format showJSRational :: Rational -> ShowS -- | Show a list in JSON format showJSArray :: [JSValue] -> ShowS -- | Show an association list in JSON format showJSObject :: JSObject JSValue -> ShowS -- | Show JSON values showJSValue :: JSValue -> ShowS makeObj :: [(String, JSValue)] -> JSValue -- | Pull a value out of a JSON object. valFromObj :: (JSON a) => String -> JSObject JSValue -> Result a instance (Eq a) => Eq (Result a) instance (Show a) => Show (Result a) instance JSON ByteString instance JSON ByteString instance JSON IntSet instance (Ord a, JSON a, JSON b) => JSON (Map a b) instance (JSON a) => JSON [a] instance (JSON a, JSON b, JSON c, JSON d) => JSON (a, b, c, d) instance (JSON a, JSON b, JSON c) => JSON (a, b, c) instance (JSON a, JSON b) => JSON (a, b) instance JSON () instance (JSON a, JSON b) => JSON (Either a b) instance (JSON a) => JSON (Maybe a) instance JSON Float instance JSON Double instance JSON Int64 instance JSON Int32 instance JSON Int16 instance JSON Int8 instance JSON Word64 instance JSON Word32 instance JSON Word16 instance JSON Word8 instance JSON Word instance JSON Int instance JSON Integer instance JSON Ordering instance JSON Char instance JSON Bool instance (JSON a) => JSON (JSObject a) instance JSON JSString instance JSON JSValue instance Monad Result instance MonadPlus Result instance Alternative Result instance Applicative Result instance Functor Result