support aeson for Map

Make unused --json use it, which is better than the doubly nested lists
it was using.

Sponsored-By: the NIH-funded NICEMAN (ReproNim TR&D3) project
This commit is contained in:
Joey Hess 2023-05-10 13:30:43 -04:00
parent 8d8e044458
commit 9812d9aaec
No known key found for this signature in database
GPG key ID: DB12DB0FF05F8F38
2 changed files with 9 additions and 2 deletions

View file

@ -40,6 +40,7 @@ import qualified Data.Map as M
import qualified Data.Vector as V
import qualified Data.ByteString as S
import qualified Data.ByteString.Char8 as S8
import qualified Data.Text as T
import Data.Char
cmd :: Command
@ -116,7 +117,7 @@ check fileprefix msg a c = do
showLongNote $ UnquotedString $ msg unusedlist
maybeAddJSONField
((if null fileprefix then "unused" else fileprefix) ++ "-list")
(V.fromList $ map (\(n, k) -> (show n, serializeKey k)) unusedlist)
(M.fromList $ map (\(n, k) -> (T.pack (show n), serializeKey k)) unusedlist)
updateUnusedLog (toRawFilePath fileprefix) (M.fromList unusedlist)
return $ c + length l

View file

@ -2,7 +2,7 @@
-
- Import instead of Data.Aeson
-
- Copyright 2018-2019 Joey Hess <id@joeyh.name>
- Copyright 2018-2023 Joey Hess <id@joeyh.name>
-
- License: BSD-2-clause
-}
@ -33,6 +33,7 @@ import qualified Data.Text.Encoding as T
import qualified Data.ByteString.Lazy as L
import qualified Data.ByteString as S
import qualified Data.Set
import qualified Data.Map
import qualified Data.Vector
import Prelude
@ -100,6 +101,11 @@ instance ToJSON' s => ToJSON' (Data.Vector.Vector s) where
instance ToJSON' s => ToJSON' (Data.Set.Set s) where
toJSON' = toJSON . map toJSON' . Data.Set.toList
instance (ToJSON' v) => ToJSON' (Data.Map.Map T.Text v) where
toJSON' m = object $ map go (Data.Map.toList m)
where
go (k, v) = (textKey k, toJSON' v)
instance (ToJSON' a, ToJSON a) => ToJSON' (Maybe a) where
toJSON' (Just a) = toJSON (Just (toJSON' a))
toJSON' v@Nothing = toJSON v