-
Notifications
You must be signed in to change notification settings - Fork 0
/
SimpleJSON.hs
43 lines (36 loc) · 987 Bytes
/
SimpleJSON.hs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
module SimpleJSON (
JValue (..)
, getString
, getInt
, getDouble
, getBool
, getObject
, getArray
, isNull
) where
data JValue
= JString String
| JBool Bool
| JNumber Double
| JNull
| JObject [(String, JValue)]
| JArray [JValue]
deriving (Eq, Ord, Show)
getString :: JValue -> Maybe String
getString (JString s) = Just s
getString _ = Nothing
getBool :: JValue -> Maybe Bool
getBool (JBool b) = Just b
getBool _ = Nothing
getDouble :: JValue -> Maybe Double
getDouble (JNumber d) = Just d
getDouble _ = Nothing
getInt :: JValue -> Maybe Int
getInt (JNumber i) = Just (truncate i)
getInt _ = Nothing
-- copypaste
getObject (JObject o) = Just o
getObject _ = Nothing
getArray (JArray a) = Just a
getArray _ = Nothing
isNull v = v == JNull