packages feed

json2 0.3 → 0.3.1

raw patch · 2 files changed

+40/−24 lines, 2 filesdep +old-localedep +timePVP: major bump suggested

API removals or changes: PVP suggests a major version bump

Dependencies added: old-locale, time

API changes (from Hackage documentation)

- Data.JSON2: instance [incoherent] FromJson Rational
- Data.JSON2: instance [incoherent] ToJson Rational
+ Data.JSON2: instance [incoherent] (ToJson a, ToJson b) => ToJson (Either a b)
+ Data.JSON2: instance [incoherent] FromJson (Maybe UTCTime)
+ Data.JSON2: instance [incoherent] ToJson UTCTime
- Data.JSON2: JBool :: Bool -> Json
+ Data.JSON2: JBool :: !Bool -> Json

Files

Data/JSON2.hs view
@@ -7,13 +7,15 @@    Json(..), Jsons,    ToJson(..), FromJson(..),    -- * Building JSON objects-   emptyObj, singleObj, (==>), fromList,+   emptyObj,  (==>), fromList,    -- * Union JSON objects    unionObj, unionsObj, unionRecObj,    -- * Rendering to string    toString,-   -- * Pretty print-   pprint, pprints+   -- * Debug print+   pprint, pprints,+   -- * Deprecated+   singleObj   )  where @@ -21,14 +23,18 @@ import qualified Data.Map as Map import Data.Ratio import Data.Typeable (Typeable)+import Data.Time.Clock (UTCTime)+import Data.Time.Format (formatTime, parseTime)+import System.Locale (defaultTimeLocale) + infixr 6 ==>  -- * Data types and classes  data Json = JString String 	  | JNumber Rational-	  | JBool Bool+	  | JBool !Bool 	  | JNull 	  | JArray [Json] 	  | JObject (Map.Map String Json) deriving (Eq, Ord, Typeable, Show, Read)@@ -36,11 +42,13 @@ type Jsons = [Json]  -- | This module provides instances @ToJson@ for :--- @(), Char,  Json, Maybe, Bool, String, Integr, Int, Double, Float,--- Rational, Map String a, List, tuples 2-5 sizes@ .+-- @(), Char,  Json, Maybe, Either, Bool, String, Integr, Int, Double, Float,+-- UTCTime format: UTC YYYY-MM-DD HH:MM:SS , Map String a, List, tuples 2-5 sizes@ . ----- Example :+-- Examples : --+-- > getCurrentTime >>= print . toJson == JString "2011-01-29 12:12:39 UTC"+-- > -- > table :: [(Int, Maybe String, Bool)] -- > table = [ -- >     (1, Just "One", False),@@ -54,7 +62,7 @@  -- | This module provides instances @FromJson@ for : -- @Json, Maybe, Bool, String, Integr, Int, Double, Float,--- Rational, Map String a, List, tuples 2-5 sizes@ .+--  Maybe UTCTime ,Map String a, List, tuples 2-5 sizes@ . -- -- Example : --@@ -64,6 +72,12 @@     fromJson :: Json -> a  -- ** Instances FromJson and ToJson+--+instance ToJson UTCTime where+    toJson ut = JString $ formatTime defaultTimeLocale templateUTC ut+instance FromJson (Maybe UTCTime) where+    fromJson (JString t) =  parseTime defaultTimeLocale templateUTC t :: Maybe UTCTime+templateUTC =  "%Y-%m-%d %T UTC"  instance  ToJson () where     toJson () = JArray []@@ -81,6 +95,10 @@ instance FromJson a => FromJson (Maybe a) where     fromJson x = if x == JNull then Nothing else Just (fromJson x) +instance (ToJson a, ToJson b) => ToJson (Either a b) where+    toJson (Left a)  = toJson a+    toJson (Right b) = toJson b+ instance ToJson Bool where     toJson x = JBool x instance FromJson Bool where@@ -111,16 +129,12 @@ instance FromJson Float where     fromJson (JNumber i) = fromRational i -instance ToJson Rational where-    toJson = JNumber-instance FromJson Rational where-    fromJson (JNumber i) =  i- instance (ToJson a) => ToJson (Map.Map String a) where     toJson = JObject .  Map.map toJson instance (FromJson a) => FromJson (Map.Map String a) where     fromJson (JObject m) = Map.map fromJson m + instance (ToJson a) => ToJson [a] where     toJson = JArray . map toJson instance (FromJson a) => FromJson [a] where@@ -154,7 +168,7 @@ emptyObj :: Json emptyObj = JObject (Map.empty) --- | Create single JSON object.+-- | DEPRECATED see @(`==>`)@. singleObj :: ToJson a => String -> a -> Json singleObj k v = JObject (Map.singleton k (toJson v)) @@ -243,7 +257,7 @@ toString (JArray vs) = "[" ++ (intercalate ", " $ map (toString) vs) ++ "]" toString (JObject l) = "{" ++ (intercalate ", " $ map (\(k, v) -> toString (JString k) ++ ": " ++ toString v) (Map.toList l)) ++ "}" --- * Pretty print+-- * Debug print  -- | Pretty-prints JSON. pprint :: Json -> IO ()
json2.cabal view
@@ -1,5 +1,5 @@ Name:                json2-Version:             0.3+Version:             0.3.1 Synopsis:            This library provides support for JSON.  Category:            Data, Text, JSON Description:         This library provides support for JSON.@@ -13,14 +13,16 @@ Cabal-version:       >= 1.6  extra-source-files:-  Examples/ExampleSqlite.hs-  Examples/ExampleQuery.hs+                    Examples/ExampleSqlite.hs+                    Examples/ExampleQuery.hs  library-  Exposed-modules:     Data.JSON2-                       Data.JSON2.FromSQL-                       Data.JSON2.Query+  Exposed-modules:+                   Data.JSON2+                   Data.JSON2.FromSQL+                   Data.JSON2.Query -  Build-Depends:       base       >= 4   && < 5,-                       containers >= 0.2 && < 1-		       +  Build-Depends:   base       >= 4   && < 5,+                   containers >= 0.2 && < 1,+                   old-locale >= 1,+                   time       >= 1.1