on master help sign in
Add Encode.null
commit904847715fdad01767c2e5439615253cb3f20ab8 authorEvan Czaplicki <evancz@users.noreply.github.com> dateTue 4 Apr 2017, 12:42 (10 years ago) parent441aeba
1 file changed+11
src/Json/Encode.hs+11
src/Json/Encode.hs+11
@@ -10,6 +10,7 @@ module Json.Encode
1010 , string
1111 , bool
1212 , int
13+ , null
1314 , dict
1415 , list
1516 , (==>)
@@ -17,6 +18,7 @@ module Json.Encode
1718 where
1819
1920
21+import Prelude hiding (null)
2022import Control.Arrow ((***))
2123import qualified Data.ByteString.Char8 as BSC
2224import qualified Data.ByteString.Builder as B
@@ -37,6 +39,7 @@ data Value
3739 | String B.Builder
3840 | Boolean Bool
3941 | Integer Int
42+ | Null
4043
4144
4245array :: [Value] -> Value
@@ -69,6 +72,11 @@ int =
6972 Integer
7073
7174
75+null :: Value
76+null =
77+ Null
78+
79+
7280dict :: (k -> String) -> (v -> Value) -> Map.Map k v -> Value
7381dict encodeKey encodeValue pairs =
7482 Object $ map (encodeKey *** encodeValue) (Map.toList pairs)
@@ -131,6 +139,9 @@ encodeHelp indent value =
131139 Integer n ->
132140 B.intDec n
133141
142+ Null ->
143+ "null"
144+
134145
135146
136147-- ENCODE ARRAY