fix for Aeson 2 breaking changes

This commit is contained in:
Michele Guerini Rocco 2022-06-12 02:36:51 +02:00
parent 4e54640966
commit 387e3b05e4
Signed by: rnhmjoj
GPG Key ID: BFBAF4C975F76450
2 changed files with 9 additions and 8 deletions

View File

@ -3,21 +3,22 @@ module Json where
import Data.Aeson import Data.Aeson
import Data.Aeson.Types (parse) import Data.Aeson.Types (parse)
import Data.Text (Text, unpack) import Data.Text (unpack)
import Data.List (intercalate) import Data.List (intercalate)
import qualified Data.Vector as V import qualified Data.Vector as V
import qualified Data.HashMap.Strict as H import qualified Data.Aeson.KeyMap as K
import qualified Data.Aeson.Key as K
-- | Gets the JSON value of a key -- | Gets the JSON value of a key
(|.) :: Object -> Text -> Value (|.) :: Object -> Key -> Value
obj |. key = case parse (.: key) obj of obj |. key = case parse (.: key) obj of
Success val -> val Success val -> val
Error err -> toJSON err Error err -> toJSON err
-- | Gets the 'String' value of a key -- | Gets the 'String' value of a key
(|:) :: Object -> Text -> String (|:) :: Object -> Key -> String
obj |: key = repr (obj |. key) obj |: key = repr (obj |. key)
@ -27,7 +28,7 @@ repr obj = repr' obj 0 where
repr' val lev = repr' val lev =
case val of case val of
Array x -> intercalate ", " $ mapl (\i -> repr' i lev) x 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 String x -> unpack x
Number x -> show x Number x -> show x
Bool 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) mapl f v = V.toList (V.map f v)
newline n = if n /= 0 then id else drop 1 newline n = if n /= 0 then id else drop 1
indent l = '\n' : (concat . replicate l) " " 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' -- | Pretty print a JSON 'Value'

View File

@ -20,7 +20,7 @@ import qualified Data.Text.IO as T
-- Data manipulation -- Data manipulation
import Data.Text (Text) import Data.Text (Text)
import Data.Aeson (Value(..), encode, decode, toJSON) import Data.Aeson (Value(..), encode, decode, toJSON)
import Data.HashMap.Strict (delete) import Data.Aeson.KeyMap (delete)
import Data.ByteString.Lazy.Char8 (pack, unpack) import Data.ByteString.Lazy.Char8 (pack, unpack)
-- Misc -- Misc