From 1a746adad23fc91ac95465b248b0e88aea06757a Mon Sep 17 00:00:00 2001 From: justin Date: Mon, 1 May 2023 10:27:16 +0100 Subject: [PATCH] Add file --- src/AesonHelp.hs | 23 +++++++++++++++++++++++ 1 file changed, 23 insertions(+) create mode 100644 src/AesonHelp.hs diff --git a/src/AesonHelp.hs b/src/AesonHelp.hs new file mode 100644 index 000000000..7fc263d0b --- /dev/null +++ b/src/AesonHelp.hs @@ -0,0 +1,23 @@ +module AesonHelp where +import Data.Aeson (ToJSON) +import qualified Data.Aeson.Encode.Pretty as AEP +import Data.ByteString.Lazy.Char8 (unpack) +import Data.Maybe + +getPretty :: ToJSON a => a -> [String] +getPretty = lines . unpack . AEP.encodePretty' (AEP.Config (AEP.Spaces 2) compare AEP.Generic False) + +getPrettyShort :: ToJSON a => a -> [String] +getPrettyShort = mapMaybe cullPretty . getPretty + +cullPretty :: String -> Maybe String +cullPretty s = case dropWhile (== ' ') s of + ']':_ -> Nothing + '[':_ -> Nothing + '}':_ -> Nothing + '{':_ -> Nothing + _ -> Just $ filter f s + where + f '_' = False + f '"' = False + f _ = True