summaryrefslogtreecommitdiffstats
path: root/PrettyJSON.hs
blob: 8fe243b39ed18773087be7f20aef40765b4a35e5 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
module PrettyJSON where
import Text.JSON
import Text.PrettyPrint

renderJSON (JSArray vals) = brackets $ fsep $ punctuate comma $ map renderJSON vals

renderJSON (JSObject jsObject) = 
  let object = fromJSObject jsObject
  in braces $ fsep $ punctuate comma $ 
     [hang (renderJSON (JSString $ toJSString $ k) <> colon) 2 (renderJSON v)
     | (k,v) <- object]
renderJSON x = text $ encode x