fix for Aeson 2 breaking changes
This commit is contained in:
parent
4e54640966
commit
387e3b05e4
15
src/Json.hs
15
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'
|
||||
|
@ -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
|
||||
|
Loading…
Reference in New Issue
Block a user