From e39d728af0af136f8b89641fa2d6473f2d79677c Mon Sep 17 00:00:00 2001 From: Rob Rix Date: Mon, 29 Feb 2016 17:33:19 -0500 Subject: [PATCH] Write a custom Show instance for JSObject. --- src/Text/JSON.hs | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/src/Text/JSON.hs b/src/Text/JSON.hs index 4f21209ec..a26c6c283 100644 --- a/src/Text/JSON.hs +++ b/src/Text/JSON.hs @@ -1,5 +1,7 @@ module Text.JSON where +import Data.List + data JSValue = JSNull | JSBool !Bool @@ -19,7 +21,11 @@ toJSString :: String -> JSString toJSString = JSONString newtype JSObject value = JSONObject { fromJSObject :: [(String, value)] } - deriving (Eq, Show) + deriving (Eq) + +instance Show value => Show (JSObject value) where + show (JSONObject pairs) = "{" ++ intercalate "," (showPair <$> pairs) ++ "}" + where showPair (key, value) = show (toJSString key) ++ ":" ++ show value toJSObject :: [(String, value)] -> JSObject value toJSObject = JSONObject