Files
loop/src/AesonHelp.hs
T
2023-05-01 10:27:16 +01:00

24 lines
647 B
Haskell

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