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
|
module JSON.Pretty (ppJSON, ppJValue) where
import JSON.Data
import Pretty
ppJSON :: JValue -> String
ppJSON j = pPrint (ppJValue j)
ppJValue :: JValue -> Doc
ppJValue JTrue = text "true"
ppJValue JFalse = text "false"
ppJValue JNull = text "null"
ppJValue (JNumber f) = float f
ppJValue (JString s) = text $ show s
ppJValue (JArray vs) = ppJArray vs
ppJValue (JObject ps) = ppJObject ps
ppJArray :: [JValue] -> Doc
ppJArray vs = listSpaced $ map ppJValue vs
ppJObject :: [(String, JValue)] -> Doc
ppJObject ps = (nest 2 $ lbrace $$ vsep (punctuate comma $ map ppKVP ps)) $$ rbrace
where ppKVP (k, v) = (text $ show k) <> colon <+> ppJValue v
|