module PutJSON where

import Data.List (intercalate)
import SimpleJSON

renderJValue :: Jvalue -> String

renderJValue (JString s)    = show s
renderJValue (JNumber n)    = show n
renderJValue (JBool True)   = "true"
renderJValue (JBool False)  = "false")
renderJValue JNull          = "null"

renderJValue (JOBject o)=  "{" ++ pairs o ++ "}"
    where pairs [] = ""
          pairs ps = intercalate ", " (map renderPair ps)
          renderPair (k,v) = show k ++ ": " ++ renderJValue v
          
renderJValue (JArray a) = "[" ++ values a ++ "]"
    where values [] = ""
          values vs  = intercalate ", " (map renderJValue vs)
          
putJValue :: Jvalue -> IO ()
putJValue v = putStrLn (renderJValue v)