From 387e3b05e48bedacb9944cc2f11ef3f8ede83bc7 Mon Sep 17 00:00:00 2001 From: rnhmjoj Date: Sun, 12 Jun 2022 02:36:51 +0200 Subject: [PATCH] fix for Aeson 2 breaking changes --- src/Json.hs | 15 ++++++++------- src/Main.hs | 2 +- 2 files changed, 9 insertions(+), 8 deletions(-) diff --git a/src/Json.hs b/src/Json.hs index f2ffa8f..087ab65 100644 --- a/src/Json.hs +++ b/src/Json.hs @@ -3,21 +3,22 @@ module Json where import Data.Aeson import Data.Aeson.Types (parse) -import Data.Text (Text, unpack) +import Data.Text (unpack) import Data.List (intercalate) -import qualified Data.Vector as V -import qualified Data.HashMap.Strict as H +import qualified Data.Vector as V +import qualified Data.Aeson.KeyMap as K +import qualified Data.Aeson.Key as K -- | Gets the JSON value of a key -(|.) :: Object -> Text -> Value +(|.) :: Object -> Key -> Value obj |. key = case parse (.: key) obj of Success val -> val Error err -> toJSON err -- | Gets the 'String' value of a key -(|:) :: Object -> Text -> String +(|:) :: Object -> Key -> String obj |: key = repr (obj |. key) @@ -27,7 +28,7 @@ repr obj = repr' obj 0 where repr' val lev = case val of Array x -> intercalate ", " $ mapl (\i -> repr' i lev) x - Object x -> newline lev $ concat $ map (dump x lev) $ H.keys x + Object x -> newline lev $ concat $ map (dump x lev) $ K.keys x String x -> unpack x Number x -> show x Bool x -> show x @@ -35,7 +36,7 @@ repr obj = repr' obj 0 where mapl f v = V.toList (V.map f v) newline n = if n /= 0 then id else drop 1 indent l = '\n' : (concat . replicate l) " " - dump o l k = concat [indent l, unpack k, ": ", repr' (o |. k) (l+1)] + dump o l k = concat [indent l, K.toString k, ": ", repr' (o |. k) (l+1)] -- | Pretty print a JSON 'Value' diff --git a/src/Main.hs b/src/Main.hs index 46f3f29..ec9efb8 100644 --- a/src/Main.hs +++ b/src/Main.hs @@ -20,7 +20,7 @@ import qualified Data.Text.IO as T -- Data manipulation import Data.Text (Text) import Data.Aeson (Value(..), encode, decode, toJSON) -import Data.HashMap.Strict (delete) +import Data.Aeson.KeyMap (delete) import Data.ByteString.Lazy.Char8 (pack, unpack) -- Misc