module SimpleJSON
    (JValue(..)
    ,getString
    ,getNumber
    ,getBool
    ,getObject
    ,getArray
    ,isNull
    )where

data JValue = JString String
            | JNumber Double
            | JBool Bool
            | JNull
            | JObject [(String, JValue)]
            | JArray [JValue]
              deriving (Eq, Ord, Show)

getString :: JValue -> Maybe String
getString (JString s) = Just s
getString _           = Nothing

getNumber :: JValue -> Maybe Int
getNumber (JNumber d) = Just $ truncate d
getNumber _           = Nothing

getBool :: JValue -> Maybe Bool
getBool (JBool b) = Just b
getBool _         = Nothing

isNull :: JValue -> Bool
isNull v = v == JNull

getObject :: JValue -> Maybe [(String, JValue)]
getObject (JObject o) = Just o
getObject _           = Nothing

getArray :: JValue -> Maybe [JValue]
getArray (JArray a) = Just a
getArray _          = Nothing

