-- Hoogle documentation, generated by Haddock -- See Hoogle, http://www.haskell.org/hoogle/ -- | Serialising to and from JSON5 -- -- The JSON5 Data Interchange Format (JSON5) is a superset of JSON that -- aims to alleviate some of the limitations of JSON by expanding its -- syntax to include some productions from ECMAScript 5.1. -- -- This library provides a parser and pretty printer for converting -- between Haskell values and JSON5. @package json5hs @version 0.1.2.2 -- | The types to encode Haskell values. module Text.JSON5.Types data JSValue JSNull :: JSValue JSBool :: !Bool -> JSValue JSNumber :: JSNumber -> JSValue JSString :: JSString -> JSValue JSArray :: [JSValue] -> JSValue JSObject :: JSObject JSValue -> JSValue data JSNumber JSRational :: !Rational -> JSNumber JSInfNaN :: !Float -> JSNumber fromJSRational :: Rational -> JSValue fromJSInfNaN :: Float -> JSValue newtype JSString JSONString :: String -> JSString [fromJSString] :: JSString -> String toJSString :: String -> JSString newtype JSObject a JSONObject :: [(String, a)] -> JSObject a [fromJSObject] :: JSObject a -> [(String, a)] toJSObject :: [(String, a)] -> JSObject a get_field :: JSObject a -> String -> Maybe a set_field :: JSObject a -> String -> a -> JSObject a instance GHC.Read.Read Text.JSON5.Types.JSValue instance GHC.Show.Show Text.JSON5.Types.JSValue instance GHC.Classes.Ord Text.JSON5.Types.JSValue instance GHC.Classes.Eq Text.JSON5.Types.JSValue instance GHC.Read.Read a => GHC.Read.Read (Text.JSON5.Types.JSObject a) instance GHC.Show.Show a => GHC.Show.Show (Text.JSON5.Types.JSObject a) instance GHC.Classes.Ord a => GHC.Classes.Ord (Text.JSON5.Types.JSObject a) instance GHC.Classes.Eq a => GHC.Classes.Eq (Text.JSON5.Types.JSObject a) instance GHC.Read.Read Text.JSON5.Types.JSString instance GHC.Show.Show Text.JSON5.Types.JSString instance GHC.Classes.Ord Text.JSON5.Types.JSString instance GHC.Classes.Eq Text.JSON5.Types.JSString instance GHC.Read.Read Text.JSON5.Types.JSNumber instance GHC.Show.Show Text.JSON5.Types.JSNumber instance GHC.Classes.Ord Text.JSON5.Types.JSNumber instance GHC.Classes.Eq Text.JSON5.Types.JSNumber instance Data.String.IsString Text.JSON5.Types.JSValue instance Data.String.IsString Text.JSON5.Types.JSString -- | Basic support for working with JSON5 values. module Text.JSON5.String -- | Parsing JSON5 -- -- The type of JSON5 parsers for String data GetJSON a -- | Run a JSON5 reader on an input String, returning some Haskell value. -- All input will be consumed. runGetJSON :: GetJSON a -> String -> Either String a -- | Read the JSON5 null type readJSNull :: GetJSON JSValue -- | Read the JSON5 Bool type readJSBool :: GetJSON JSValue -- | Strings -- -- Read the JSON5 String type readJSString :: Char -> GetJSON JSValue -- | Numbers -- -- Read an Integer or Double in JSON5 format, returning a Rational readJSRational :: GetJSON Rational -- | Read an Infinity or NaN in JSON5 format, returning a Float readJSInfNaN :: GetJSON Float -- | Objects & Arrays -- -- Read a list in JSON5 format readJSArray :: GetJSON JSValue -- | Read an object in JSON5 format readJSObject :: GetJSON JSValue -- | Read one of several possible JS types readJSValue :: GetJSON JSValue -- | Top level JSON5 can only be Arrays or Objects readJSTopType :: GetJSON JSValue -- | Write the JSON5 null type showJSNull :: ShowS -- | Write the JSON5 Bool type showJSBool :: Bool -> ShowS -- | Show a list in JSON format showJSArray :: [JSValue] -> ShowS -- | Show an association list in JSON format showJSObject :: JSObject JSValue -> ShowS -- | Show a Rational in JSON5 format showJSRational :: Rational -> ShowS -- | Show a Infinity or NaN in JSON5 format showJSInfNaN :: Float -> ShowS -- | Show JSON5 values showJSValue :: JSValue -> ShowS -- | Writing JSON5 -- -- Show strict JSON5 top level types. Values not permitted at the top -- level are wrapped in a singleton array. showJSTopType :: JSValue -> ShowS instance GHC.Base.Functor Text.JSON5.String.GetJSON instance GHC.Base.Applicative Text.JSON5.String.GetJSON instance GHC.Base.Monad Text.JSON5.String.GetJSON -- | Display JSON5 values using pretty printing combinators. module Text.JSON5.Pretty ppJSValue :: JSValue -> Doc ppNull :: Doc ppBoolean :: Bool -> Doc ppJSNumber :: JSNumber -> Doc ppRational :: Rational -> Doc ppInfNaN :: Float -> Doc ppArray :: [JSValue] -> Doc ppString :: String -> Doc ppObject :: [(String, JSValue)] -> Doc ppJSString :: JSString -> Doc ppJSObject :: JSObject JSValue -> Doc -- | Serialising Haskell values to and from JSON5 values. module Text.JSON5 data JSValue JSNull :: JSValue JSBool :: !Bool -> JSValue JSNumber :: JSNumber -> JSValue JSString :: JSString -> JSValue JSArray :: [JSValue] -> JSValue JSObject :: JSObject JSValue -> JSValue -- | The class of types serialisable to and from JSON5 class JSON5 a readJSON :: JSON5 a => JSValue -> Result a showJSON :: JSON5 a => a -> JSValue readJSONs :: JSON5 a => JSValue -> Result [a] showJSONs :: JSON5 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 JSON5 format. -- -- This is a superset of JSON5, as types other than Array and Object are -- allowed at the top level. encode :: JSON5 a => a -> String -- | Decode a String representing a JSON5 value (either an object, array, -- bool, number, null) -- -- This is a superset of JSON5, as types other than Array and Object are -- allowed at the top level. decode :: JSON5 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. JSON5 types to be an Array or Object. encodeStrict :: JSON5 a => a -> String -- | Decode a String representing a strict JSON value. This follows the -- spec, and requires top level JSON5 types to be an Array or Object. decodeStrict :: JSON5 a => String -> Result a data JSString toJSString :: String -> JSString fromJSString :: JSString -> String data JSObject a toJSObject :: [(String, a)] -> JSObject a fromJSObject :: JSObject a -> [(String, a)] -- | Map Results to Eithers resultToEither :: Result a -> Either String a -- | Read the JSON5 null type readJSNull :: GetJSON JSValue -- | Read the JSON5 Bool type readJSBool :: GetJSON JSValue -- | Strings -- -- Read the JSON5 String type readJSString :: Char -> GetJSON JSValue -- | Numbers -- -- Read an Integer or Double in JSON5 format, returning a Rational readJSRational :: GetJSON Rational -- | Objects & Arrays -- -- Read a list in JSON5 format readJSArray :: GetJSON JSValue -- | Read an object in JSON5 format readJSObject :: GetJSON JSValue -- | Read one of several possible JS types readJSValue :: GetJSON JSValue -- | Write the JSON5 null type showJSNull :: ShowS -- | Write the JSON5 Bool type showJSBool :: Bool -> ShowS -- | Show a list in JSON format showJSArray :: [JSValue] -> ShowS -- | Show a Rational in JSON5 format showJSRational :: Rational -> ShowS -- | Show a Infinity or NaN in JSON5 format showJSInfNaN :: Float -> ShowS -- | Show an association list in JSON format showJSObject :: JSObject JSValue -> ShowS -- | Show JSON5 values showJSValue :: JSValue -> ShowS makeObj :: [(String, JSValue)] -> JSValue -- | Pull a value out of a JSON5 object. valFromObj :: JSON5 a => String -> JSObject JSValue -> Result a -- | Haskell types that can be used as keys in JSON5 objects. class JSKey a toJSKey :: JSKey a => a -> String fromJSKey :: JSKey a => String -> Maybe a -- | Encode an association list as JSValue value. encJSDict :: (JSKey a, JSON5 b) => [(a, b)] -> JSValue -- | Decode a JSValue value into an association list. decJSDict :: (JSKey a, JSON5 b) => String -> JSValue -> Result [(a, b)] instance GHC.Show.Show a => GHC.Show.Show (Text.JSON5.Result a) instance GHC.Classes.Eq a => GHC.Classes.Eq (Text.JSON5.Result a) instance Text.JSON5.JSKey Text.JSON5.Types.JSString instance Text.JSON5.JSKey GHC.Types.Int instance Text.JSON5.JSKey GHC.Base.String instance Text.JSON5.JSON5 Text.JSON5.Types.JSValue instance Text.JSON5.JSON5 Text.JSON5.Types.JSString instance Text.JSON5.JSON5 a => Text.JSON5.JSON5 (Text.JSON5.Types.JSObject a) instance Text.JSON5.JSON5 GHC.Types.Bool instance Text.JSON5.JSON5 GHC.Types.Char instance Text.JSON5.JSON5 GHC.Types.Ordering instance Text.JSON5.JSON5 GHC.Integer.Type.Integer instance Text.JSON5.JSON5 GHC.Types.Int instance Text.JSON5.JSON5 GHC.Types.Word instance Text.JSON5.JSON5 GHC.Word.Word8 instance Text.JSON5.JSON5 GHC.Word.Word16 instance Text.JSON5.JSON5 GHC.Word.Word32 instance Text.JSON5.JSON5 GHC.Word.Word64 instance Text.JSON5.JSON5 GHC.Int.Int8 instance Text.JSON5.JSON5 GHC.Int.Int16 instance Text.JSON5.JSON5 GHC.Int.Int32 instance Text.JSON5.JSON5 GHC.Int.Int64 instance Text.JSON5.JSON5 GHC.Types.Double instance Text.JSON5.JSON5 GHC.Types.Float instance Text.JSON5.JSON5 a => Text.JSON5.JSON5 (GHC.Maybe.Maybe a) instance (Text.JSON5.JSON5 a, Text.JSON5.JSON5 b) => Text.JSON5.JSON5 (Data.Either.Either a b) instance Text.JSON5.JSON5 () instance (Text.JSON5.JSON5 a, Text.JSON5.JSON5 b) => Text.JSON5.JSON5 (a, b) instance (Text.JSON5.JSON5 a, Text.JSON5.JSON5 b, Text.JSON5.JSON5 c) => Text.JSON5.JSON5 (a, b, c) instance (Text.JSON5.JSON5 a, Text.JSON5.JSON5 b, Text.JSON5.JSON5 c, Text.JSON5.JSON5 d) => Text.JSON5.JSON5 (a, b, c, d) instance Text.JSON5.JSON5 a => Text.JSON5.JSON5 [a] instance (GHC.Classes.Ord a, Text.JSON5.JSON5 a, Text.JSON5.JSON5 b) => Text.JSON5.JSON5 (Data.Map.Internal.Map a b) instance Text.JSON5.JSON5 a => Text.JSON5.JSON5 (Data.IntMap.Internal.IntMap a) instance (GHC.Classes.Ord a, Text.JSON5.JSON5 a) => Text.JSON5.JSON5 (Data.Set.Internal.Set a) instance (GHC.Arr.Ix i, Text.JSON5.JSON5 i, Text.JSON5.JSON5 e) => Text.JSON5.JSON5 (GHC.Arr.Array i e) instance Text.JSON5.JSON5 Data.IntSet.Internal.IntSet instance Text.JSON5.JSON5 Data.ByteString.Internal.ByteString instance Text.JSON5.JSON5 Data.ByteString.Lazy.Internal.ByteString instance Text.JSON5.JSON5 Data.Text.Internal.Text instance GHC.Base.Functor Text.JSON5.Result instance GHC.Base.Applicative Text.JSON5.Result instance GHC.Base.Alternative Text.JSON5.Result instance GHC.Base.MonadPlus Text.JSON5.Result instance GHC.Base.Monad Text.JSON5.Result -- | JSON5 serializer and deserializer using Data.Generics. The functions -- here handle algebraic data types and primitive types. It uses the same -- representation as Text.JSON5 for Prelude types. module Text.JSON5.Generic -- | The Data class comprehends a fundamental primitive -- gfoldl for folding over constructor applications, say terms. -- This primitive can be instantiated in several ways to map over the -- immediate subterms of a term; see the gmap combinators later -- in this class. Indeed, a generic programmer does not necessarily need -- to use the ingenious gfoldl primitive but rather the intuitive -- gmap combinators. The gfoldl primitive is completed by -- means to query top-level constructors, to turn constructor -- representations into proper terms, and to list all possible datatype -- constructors. This completion allows us to serve generic programming -- scenarios like read, show, equality, term generation. -- -- The combinators gmapT, gmapQ, gmapM, etc are all -- provided with default definitions in terms of gfoldl, leaving -- open the opportunity to provide datatype-specific definitions. (The -- inclusion of the gmap combinators as members of class -- Data allows the programmer or the compiler to derive -- specialised, and maybe more efficient code per datatype. Note: -- gfoldl is more higher-order than the gmap combinators. -- This is subject to ongoing benchmarking experiments. It might turn out -- that the gmap combinators will be moved out of the class -- Data.) -- -- Conceptually, the definition of the gmap combinators in terms -- of the primitive gfoldl requires the identification of the -- gfoldl function arguments. Technically, we also need to -- identify the type constructor c for the construction of the -- result type from the folded term type. -- -- In the definition of gmapQx combinators, we use -- phantom type constructors for the c in the type of -- gfoldl because the result type of a query does not involve the -- (polymorphic) type of the term argument. In the definition of -- gmapQl we simply use the plain constant type constructor -- because gfoldl is left-associative anyway and so it is readily -- suited to fold a left-associative binary operation over the immediate -- subterms. In the definition of gmapQr, extra effort is needed. We use -- a higher-order accumulation trick to mediate between left-associative -- constructor application vs. right-associative binary operation (e.g., -- (:)). When the query is meant to compute a value of type -- r, then the result type withing generic folding is r -- -> r. So the result of folding is a function to which we -- finally pass the right unit. -- -- With the -XDeriveDataTypeable option, GHC can generate -- instances of the Data class automatically. For example, given -- the declaration -- --
--   data T a b = C1 a b | C2 deriving (Typeable, Data)
--   
-- -- GHC will generate an instance that is equivalent to -- --
--   instance (Data a, Data b) => Data (T a b) where
--       gfoldl k z (C1 a b) = z C1 `k` a `k` b
--       gfoldl k z C2       = z C2
--   
--       gunfold k z c = case constrIndex c of
--                           1 -> k (k (z C1))
--                           2 -> z C2
--   
--       toConstr (C1 _ _) = con_C1
--       toConstr C2       = con_C2
--   
--       dataTypeOf _ = ty_T
--   
--   con_C1 = mkConstr ty_T "C1" [] Prefix
--   con_C2 = mkConstr ty_T "C2" [] Prefix
--   ty_T   = mkDataType "Module.T" [con_C1, con_C2]
--   
-- -- This is suitable for datatypes that are exported transparently. class Typeable a => Data a -- | The class Typeable allows a concrete representation of a type -- to be calculated. class Typeable (a :: k) -- | Convert anything to a JSON5 value. toJSON :: Data a => a -> JSValue -- | Convert a JSON5 value to anything (fails if the types do not match). fromJSON :: Data a => JSValue -> Result a -- | Encode a value as a string. encodeJSON :: Data a => a -> String -- | Decode a string as a value. decodeJSON :: Data a => String -> a toJSON_generic :: Data a => a -> JSValue fromJSON_generic :: Data a => JSValue -> Result a