on master help sign in
Add Encode.null
9048477Evan Czaplicki
src/Json/Encode.hs+11
@@ -10,6 +10,7 @@ module Json.Encode
10 , string
10 , string
11 , bool
11 , bool
12 , int
12 , int
13+ , null
13 , dict
14 , dict
14 , list
15 , list
15 , (==>)
16 , (==>)
@@ -17,6 +18,7 @@ module Json.Encode
17 where
18 where
18
19
19
20
21+import Prelude hiding (null)
20import Control.Arrow ((***))
22import Control.Arrow ((***))
21import qualified Data.ByteString.Char8 as BSC
23import qualified Data.ByteString.Char8 as BSC
22import qualified Data.ByteString.Builder as B
24import qualified Data.ByteString.Builder as B
@@ -37,6 +39,7 @@ data Value
37 | String B.Builder
39 | String B.Builder
38 | Boolean Bool
40 | Boolean Bool
39 | Integer Int
41 | Integer Int
42+ | Null
40
43
41
44
42array :: [Value] -> Value
45array :: [Value] -> Value
@@ -69,6 +72,11 @@ int =
69 Integer
72 Integer
70
73
71
74
75+null :: Value
76+null =
77+ Null
78+
79+
72dict :: (k -> String) -> (v -> Value) -> Map.Map k v -> Value
80dict :: (k -> String) -> (v -> Value) -> Map.Map k v -> Value
73dict encodeKey encodeValue pairs =
81dict encodeKey encodeValue pairs =
74 Object $ map (encodeKey *** encodeValue) (Map.toList pairs)
82 Object $ map (encodeKey *** encodeValue) (Map.toList pairs)
@@ -131,6 +139,9 @@ encodeHelp indent value =
131 Integer n ->
139 Integer n ->
132 B.intDec n
140 B.intDec n
133
141
142+ Null ->
143+ "null"
144+
134
145
135
146
136-- ENCODE ARRAY
147-- ENCODE ARRAY