-- Hoogle documentation, generated by Haddock -- See Hoogle, http://www.haskell.org/hoogle/ -- | Library provides support for JSON. -- -- This library provides support for JSON. @package json2 @version 0.8.3 -- | Efficient build ByteString from Json with escaped string. -- -- For example - use in YESOD: -- --
--   import Yesod
--   import Data.JSON2       as JSON
--   import Data.JSON2.Blaze as JSON
--   import Blaze.ByteString.Builder (toLazyByteString)
--   --
--   toRepJson :: ToJson a => a -> RepJson
--   toRepJson =  RepJson . toContent . toLazyByteString . (JSON.blazeJson) . (JSON.toJson)
--   
module Data.JSON2.Blaze blazeJson :: Json -> Builder -- | See also: -- http://www.haskell.org/haskellwiki/HXT#The_concept_of_filters module Data.JSON2.Query type JFilter = Json -> Jsons -- | Filter Json strings. isStr :: JFilter -- | Predicative filter Json strings. isStrBy :: (String -> Bool) -> JFilter -- | Filter Json numbers. isNum :: JFilter -- | Predicative filter Json numbers. isNumBy :: Fractional a => (a -> Bool) -> JFilter -- | Filter Json Bool. isBool :: JFilter -- | Filter Json True. isTrue :: JFilter -- | Filter Json False. isFalse :: JFilter -- | Filter Json null. isNull :: JFilter -- | Filter primitive types. isAtomic :: JFilter -- | Filter Json objects. isObj :: JFilter -- | Get all elements from object. getFromObj :: JFilter -- | Get elements from object with key. getFromKey :: String -> JFilter -- | Get elements from object with keys. getFromKeys :: [String] -> JFilter -- | Get elements from object with key by. getFromKeyBy :: (String -> Bool) -> JFilter -- | Filter Json arrays. isArr :: JFilter -- | Get all elements from array. getFromArr :: JFilter -- | Get element from array with index. getFromIndex :: Int -> JFilter -- | Get elements from array with index by. -- -- DEPRECATED use: getFromIndexBy getFromIndexes :: [Int] -> JFilter -- | Get elements from array with indexes. getFromIndexBy :: (Int -> Bool) -> JFilter -- | Get all elements from object and array. getChildern :: JFilter -- | (f >>> g) - Apply filter f, later filter g . (>>>) :: JFilter -> JFilter -> JFilter -- | Concat results two filters. (<+>) :: JFilter -> JFilter -> JFilter -- | (f orElse g) - Apply f, if f returned -- empty apply g. orElse :: JFilter -> JFilter -> JFilter -- | (f when g) - When g returned not -- empty, apply f. when :: JFilter -> JFilter -> JFilter -- | (f guards g ) - If f returned empty -- then empty else apply g. guards :: JFilter -> JFilter -> JFilter -- | Tree traversal filter for object and array. deep :: JFilter -> JFilter -- | Tree traversal filter for array. deepObj :: JFilter -> JFilter deepArr :: JFilter -> JFilter module Data.JSON2.Parser -- | Encode String to Json. encodeJson :: String -> Json -- | Parses JSON string. parseJson :: String -> Either ParseError Json module Data.JSON2.Internal type ConvResult a = Either ConvError a -- | Conversion Rational number to Integral number with check -- bounds. checkBoundsIntegral :: (Typeable a, Bounded a, Integral a) => (Rational -> a) -> Rational -> ConvResult a -- | Conversion Rational number to Bounded values with check -- bounds. checkBoundsEnum (toEnum . round) checkBoundsEnum :: (Typeable a, Bounded a, Enum a) => (Rational -> a) -> Rational -> ConvResult a -- | Conversion Rational to RealFloat values with check -- infinity. checkInfinite :: (Typeable a, RealFloat a) => (Rational -> a) -> Rational -> ConvResult a data ConvError ConvError :: String -> String -> String -> String -> ConvError -- | Create conversion error. mkError :: (Show a, Typeable a, Typeable b) => a -> ConvResult b -- | Create conversion error with message. mkError' :: (Show a, Typeable a, Typeable b) => String -> a -> ConvResult b instance Eq ConvError instance Read ConvError instance Show ConvError instance Error ConvError -- | Class and Instances for pretty printing Your data. -- -- Minimal definition for instances Pretty - method pp -- . module Data.JSON2.Pretty class Show a => Pretty a pp :: Pretty a => a -> Doc pprint :: Pretty a => a -> String instance [incoherent] Pretty Json instance [incoherent] (Pretty a, Pretty b, Pretty c, Pretty d, Pretty e) => Pretty (a, b, c, d, e) instance [incoherent] (Pretty a, Pretty b, Pretty c, Pretty d) => Pretty (a, b, c, d) instance [incoherent] (Pretty a, Pretty b, Pretty c) => Pretty (a, b, c) instance [incoherent] (Pretty a, Pretty b) => Pretty (a, b) instance [incoherent] Pretty a => Pretty (Set a) instance [incoherent] (Pretty k, Pretty v) => Pretty (Map k v) instance [incoherent] Pretty a => Pretty [a] instance [incoherent] (Pretty a, Pretty b) => Pretty (Either a b) instance [incoherent] Pretty a => Pretty (Maybe a) instance [incoherent] Pretty String instance [incoherent] Pretty Rational instance [incoherent] Pretty Double instance [incoherent] Pretty Float instance [incoherent] Pretty Integer instance [incoherent] Pretty Int instance [incoherent] Pretty Char instance [incoherent] Pretty () -- |
    --
  1. Renders JSON to String
  2. --
-- -- Haskell value has a JSON string: -- --
--    HASKELL value                             JSON string (toString . toJson)
--   -------------------------------           -----------------------------
--   Just "bla" :: Maybe String                "bla"
--   Nothing :: Maybe String                   null
--   Left 1 :: Either Int Int                  [[1], []]
--   Right 1 :: Either Int Int                 [[], [1]]
--   'a' :: Char                               97
--   () :: ()                                  []
--   (1, "bla") :: (Int, String)               [1, "bla"]
--   fromList [1,2,3,4] :: Set Int             [1, 2, 3, 4]
--   fromList [("0",0),("1",10),("2",20)]      {"0": 0, "1": 10, "2": 20}
--       :: Map String Int
--   
-- --
    --
  1. Conversion haskell values from and to JSON
  2. --
-- -- This module provides many instances classes FromJson and -- ToJson for haskell data types. See instances class -- ToJson for SQL (HDBC) in module Database.HDBC.JSON2 (package -- json2-hdbc). -- -- Adding Instance class ToJson or FromJson -- -- Transformation of algebraic product in Json. For example: -- --
--   data Person = Person {name :: String, age:: Int}
--       deriving (Typeable, Show, Eq)
--   
-- --
--   instance ToJson Person where
--       toJson (Person s n) = toJson [toJson s, toJson n]
--   
-- --
--   instance FromJson Person where
--       safeFromJson (JArray [js, jn])
--                      = return $ Person (fromJson js) (fromJson jn)
--       safeFromJson x = mkError x
--   
-- -- Converting Bounded and Enum values to Json. For example: -- --
--   data Color = Red | Green | Blue | Black
--       deriving (Typeable, Show, Eq, Enum, Bounded)
--   
-- --
--   instance ToJson Color where
--       toJson = JNumber . toRational . fromEnum
--   instance FromJson Color where
--       safeFromJson (JNumber x) = checkBoundsEnum (toEnum . round) x
--       safeFromJson x =  mkError x
--   
module Data.JSON2 data Json :: * JString :: String -> Json JNumber :: !Rational -> Json JBool :: !Bool -> Json JNull :: Json JArray :: [Json] -> Json JObject :: Map String Json -> Json type Jsons = [Json] -- | Renders Json to String. toString :: Json -> String -- | Class for conversion from Json. class Typeable a => ToJson a toJson :: ToJson a => a -> Json -- | Class for conversion from Json. class Typeable a => FromJson a safeFromJson :: FromJson a => Json -> ConvResult a -- | Conversion from Json. fromJson :: FromJson a => Json -> a -- | Create empty Json object. emptyObj :: Json -- | Create single Json object. (.=) :: (ToJson v, Typeable v) => String -> v -> Json -- | Create Json object from list. -- --
--   ghci> pp $ mkObj [("a", "old"), ("a", "new"), ("bb", "other")]
--   {"a": "new", "bb": "other"}
--   
mkObj :: (ToJson v, Typeable v) => [(String, v)] -> Json -- | Merge two JObject. Other Json values interpreted as -- emptyObj. -- --
--   ghci > pp $ ("a" .= "old") += ("a" .= "new") += ("bb" .= "other")
--   {"a": "new", "bb": "other"}
--   
(+=) :: Json -> Json -> Json -- | Merge Json objects from list. -- --
--   ghci>  pp $ merges [("a" .= "old"), ("a" .= "new"), ("bb" .= "other")]
--   {"a": "new", "bb": "other"}
--   
merges :: [Json] -> Json -- | Recursively merge the two Json objects. mergeRec :: Json -> Json -> Json -- | Projection Json object to list of Json . -- --
--   > pp $ projectionObj ["b", "c", "b"] $ mkObj [("a",1),("b", 2), ("c", 3)]
--   [2, 3, 2]
--   
projectionObj :: [String] -> Json -> Jsons instance [incoherent] (FromJson t1, FromJson t2, FromJson t3, FromJson t4, FromJson t5) => FromJson (t1, t2, t3, t4, t5) instance [incoherent] (ToJson t1, ToJson t2, ToJson t3, ToJson t4, ToJson t5) => ToJson (t1, t2, t3, t4, t5) instance [incoherent] (FromJson t1, FromJson t2, FromJson t3, FromJson t4) => FromJson (t1, t2, t3, t4) instance [incoherent] (ToJson t1, ToJson t2, ToJson t3, ToJson t4) => ToJson (t1, t2, t3, t4) instance [incoherent] (FromJson t1, FromJson t2, FromJson t3) => FromJson (t1, t2, t3) instance [incoherent] (ToJson t1, ToJson t2, ToJson t3) => ToJson (t1, t2, t3) instance [incoherent] (FromJson t1, FromJson t2) => FromJson (t1, t2) instance [incoherent] (ToJson t1, ToJson t2) => ToJson (t1, t2) instance [incoherent] (FromJson a, Ord a) => FromJson (Set a) instance [incoherent] ToJson a => ToJson (Set a) instance [incoherent] FromJson v => FromJson (Map String v) instance [incoherent] ToJson v => ToJson (Map String v) instance [incoherent] FromJson a => FromJson [a] instance [incoherent] ToJson a => ToJson [a] instance [incoherent] FromJson Rational instance [incoherent] ToJson Rational instance [incoherent] FromJson Float instance [incoherent] ToJson Float instance [incoherent] FromJson Double instance [incoherent] ToJson Double instance [incoherent] FromJson Word64 instance [incoherent] ToJson Word64 instance [incoherent] FromJson Word32 instance [incoherent] ToJson Word32 instance [incoherent] FromJson Word16 instance [incoherent] ToJson Word16 instance [incoherent] FromJson Word8 instance [incoherent] ToJson Word8 instance [incoherent] FromJson Word instance [incoherent] ToJson Word instance [incoherent] FromJson Int64 instance [incoherent] ToJson Int64 instance [incoherent] FromJson Int32 instance [incoherent] ToJson Int32 instance [incoherent] FromJson Int16 instance [incoherent] ToJson Int16 instance [incoherent] FromJson Int8 instance [incoherent] ToJson Int8 instance [incoherent] FromJson Int instance [incoherent] ToJson Int instance [incoherent] FromJson Integer instance [incoherent] ToJson Integer instance [incoherent] FromJson Char instance [incoherent] ToJson Char instance [incoherent] FromJson ByteString instance [incoherent] ToJson ByteString instance [incoherent] FromJson ByteString instance [incoherent] ToJson ByteString instance [incoherent] FromJson String instance [incoherent] ToJson String instance [incoherent] (FromJson a, FromJson b) => FromJson (Either a b) instance [incoherent] (ToJson a, ToJson b) => ToJson (Either a b) instance [incoherent] FromJson Bool instance [incoherent] ToJson Bool instance [incoherent] FromJson a => FromJson (Maybe a) instance [incoherent] ToJson a => ToJson (Maybe a) instance [incoherent] FromJson () instance [incoherent] ToJson () instance [incoherent] FromJson Json instance [incoherent] ToJson Json -- | This module provides Instances classes ToJson and -- FromJson for Time. -- -- Time transforms to JSON as: -- --
--   Day              ["2011", "04", "03"]
--   TimeOfDay        ["13", "12", "47", ".244649"]
--   TimeZone         "EEST"
--   LocalTime        ["2011", "04", "03", "13", "12", "47", ".244649"]
--   ZonedTime        ["2011", "04", "03", "13", "12", "47", ".244649", "EEST"]
--   UTCTime          ["2011", "04", "03", "10", "12", "47", ".244777", "UTC"]
--   NominalDiffTime  1.301825863528051e9
--   POSIXTime        1.301825863528051e9
--   
module Data.JSON2.Instances.Time instance FromJson NominalDiffTime instance ToJson NominalDiffTime instance FromJson UTCTime instance ToJson UTCTime instance FromJson LocalTime instance ToJson LocalTime instance FromJson TimeZone instance ToJson TimeZone instance FromJson TimeOfDay instance ToJson TimeOfDay instance FromJson Day instance ToJson Day instance FromJson ZonedTime instance ToJson ZonedTime