packages feed

json2-types (empty) → 0.1

raw patch · 4 files changed

+121/−0 lines, 4 filesdep +basedep +containerssetup-changed

Dependencies added: base, containers

Files

+ Data/JSON2/Types.hs view
@@ -0,0 +1,65 @@+{-# LANGUAGE DeriveDataTypeable #-}++-- | Base data types and function for escape JSON string+--   and renders `Json` to `String`.++module Data.JSON2.Types+    ( Json (..)+    , Jsons (..)+    , toString+    , escJString+    )+where++import Data.Map (Map)+import qualified Data.Map as Map (toList)+import Data.Typeable (Typeable)+import Data.Ratio++data Json = JString String+	  | JNumber !Rational+	  | JBool !Bool+	  | JNull+	  | JArray [Json]+	  | JObject (Map String Json)+          deriving (Eq, Ord, Typeable, Show, Read)++type Jsons = [Json]++---------------- Renders JSON to String -------------------------++-- | Renders `Json` to String.+toString :: Json -> String+toString (JNumber x)+    | denominator x == 1 = show (numerator x)+    | otherwise          = show (fromRational x :: Double)+toString (JBool True) = "true"+toString (JBool False) = "false"+toString JNull = "null"+toString (JString x) = jStr x+toString (JArray []) = "[]"+toString (JArray (x:xs)) = concat [ "[", toString x, go, "]" ]+  where+    go = concat $ map (\x -> "," ++ toString x) xs+toString (JObject m) = concat ["{", go (Map.toList m),  "}"]+  where+    go []     = ""+    go (x:xs) = go' x ++ concat [go'' v | v <- xs]+    go' (k, v)  = concat [jStr k, ":", toString v]+    go'' (k, v) = concat [",", jStr k, ":", toString v]++jStr x = "\"" ++ escJString x ++ "\""++-- | Escape JSON string.+escJString :: String -> String+escJString = concat . map (escJChar)++escJChar c = case c of+    '\n' -> "\\n"+    '\b' -> "\\b"+    '\f' -> "\\f"+    '\t' -> "\\t"+    '\r' -> "\\r"+    '\\' -> "\\\\"+    '\"' -> "\\\""+    _    -> [c]
+ LICENSE view
@@ -0,0 +1,31 @@+Copyright (c) 2010, Yuriy Iskra+All rights reserved.++Redistribution and use in source and binary forms, with or without+modification, are permitted provided that the following conditions are+met:++    * Redistributions of source code must retain the above copyright+      notice, this list of conditions and the following disclaimer.++    * Redistributions in binary form must reproduce the above+      copyright notice, this list of conditions and the following+      disclaimer in the documentation and/or other materials provided+      with the distribution.++    * The names of its contributors may not be used to endorse or +      promote products derived from this software without specific prior +      written permission.++THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS+"AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT+LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR+A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT+OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,+SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT+LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,+DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY+THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT+(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE+OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.+
+ Setup.hs view
@@ -0,0 +1,2 @@+import Distribution.Simple+main = defaultMain
+ json2-types.cabal view
@@ -0,0 +1,23 @@+Name:                json2-types+Version:             0.1+Synopsis:            Defined JSON data types and+                     function for renders JSON to string. +Category:            Data, Text, JSON+Description:         1+Synopsis:            Defined JSON data types and+                     function for renders JSON to string.+License:             BSD3+License-file:        LICENSE+Author:              YuriyIskra+Maintainer:          YuriyIskra  <iskra.yw@gmail.com>+Stability:           Stable+Copyright:           Copyright (c) 2011 Yuriy Iskra+Build-type:          Simple+Cabal-version:       >= 1.6++library+  Exposed-modules:+                     Data.JSON2.Types++  Build-Depends:     base          >= 4   && < 5,+                     containers    >= 0.2 && < 1