    {-# LANGUAGE DeriveDataTypeable     #-}
    {-# LANGUAGE DeriveFoldable         #-}
    {-# LANGUAGE DeriveFunctor          #-}
    {-# LANGUAGE DeriveTraversable      #-}
    {-# LANGUAGE FlexibleInstances      #-}
    {-# LANGUAGE FunctionalDependencies #-}
    {-# LANGUAGE UndecidableInstances   #-}
    -----------------------------------------------------------------------------
    -- |
    -- Module      :  Data.Aeson.Extra.Map
    -- Copyright   :  (C) 2015-2016 Oleg Grenrus
    -- License     :  BSD3
    -- Maintainer  :  Oleg Grenrus <oleg.grenrus@iki.fi>
    --
    -- More or less useful newtypes for writing 'FromJSON' & 'ToJSON' instances
    module Data.Aeson.Extra.Map {-# DEPRECATED "Use aeson-1 TOJSONKey etc functionality" #-} (
      M(..),
      FromJSONKey(..),
      parseIntegralJSONKey,
      FromJSONMap(..),
      ToJSONKey(..),
      ToJSONMap(..),
      ) where

    import Prelude ()
    import Prelude.Compat

    import Data.Aeson.Compat
           (FromJSON (..), ToJSON (..), Value (..), withObject)
    import Data.Aeson.Types      (Parser)
    import Data.Hashable         (Hashable)
    import Data.Semigroup.Compat ((<>))
    import Data.Text             (Text)
    import Data.Typeable         (Typeable)

    import qualified Data.HashMap.Strict as HM
    import qualified Data.Map            as Map
    import qualified Data.Text           as T
    import qualified Data.Text.Lazy      as LT
    import qualified Data.Text.Read      as T

    -- | A wrapper type to parse arbitrary maps
    --
    -- > λ > decode "{\"1\": 1, \"2\": 2}" :: Maybe (M (H.HashMap Int Int))
    -- > Just (M {getMap = fromList [(1,1),(2,2)]})
    newtype M a = M { M a -> a
    getMap :: a }
      deriving (M a -> M a -> Bool
    (M a -> M a -> Bool) -> (M a -> M a -> Bool) -> Eq (M a)
    forall a. Eq a => M a -> M a -> Bool
    forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
    /= :: M a -> M a -> Bool
    $c/= :: forall a. Eq a => M a -> M a -> Bool
    == :: M a -> M a -> Bool
    $c== :: forall a. Eq a => M a -> M a -> Bool
    Eq, Eq (M a)
    Eq (M a) =>
    (M a -> M a -> Ordering)
    -> (M a -> M a -> Bool)
    -> (M a -> M a -> Bool)
    -> (M a -> M a -> Bool)
    -> (M a -> M a -> Bool)
    -> (M a -> M a -> M a)
    -> (M a -> M a -> M a)
    -> Ord (M a)
    M a -> M a -> Bool
    M a -> M a -> Ordering
    M a -> M a -> M a
    forall a.
    Eq a =>
    (a -> a -> Ordering)
    -> (a -> a -> Bool)
    -> (a -> a -> Bool)
    -> (a -> a -> Bool)
    -> (a -> a -> Bool)
    -> (a -> a -> a)
    -> (a -> a -> a)
    -> Ord a
    forall a. Ord a => Eq (M a)
    forall a. Ord a => M a -> M a -> Bool
    forall a. Ord a => M a -> M a -> Ordering
    forall a. Ord a => M a -> M a -> M a
    min :: M a -> M a -> M a
    $cmin :: forall a. Ord a => M a -> M a -> M a
    max :: M a -> M a -> M a
    $cmax :: forall a. Ord a => M a -> M a -> M a
    >= :: M a -> M a -> Bool
    $c>= :: forall a. Ord a => M a -> M a -> Bool
    > :: M a -> M a -> Bool
    $c> :: forall a. Ord a => M a -> M a -> Bool
    <= :: M a -> M a -> Bool
    $c<= :: forall a. Ord a => M a -> M a -> Bool
    < :: M a -> M a -> Bool
    $c< :: forall a. Ord a => M a -> M a -> Bool
    compare :: M a -> M a -> Ordering
    $ccompare :: forall a. Ord a => M a -> M a -> Ordering
    $cp1Ord :: forall a. Ord a => Eq (M a)
    Ord, Int -> M a -> ShowS
    [M a] -> ShowS
    M a -> String
    (Int -> M a -> ShowS)
    -> (M a -> String) -> ([M a] -> ShowS) -> Show (M a)
    forall a. Show a => Int -> M a -> ShowS
    forall a. Show a => [M a] -> ShowS
    forall a. Show a => M a -> String
    forall a.
    (Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
    showList :: [M a] -> ShowS
    $cshowList :: forall a. Show a => [M a] -> ShowS
    show :: M a -> String
    $cshow :: forall a. Show a => M a -> String
    showsPrec :: Int -> M a -> ShowS
    $cshowsPrec :: forall a. Show a => Int -> M a -> ShowS
    Show, ReadPrec [M a]
    ReadPrec (M a)
    Int -> ReadS (M a)
    ReadS [M a]
    (Int -> ReadS (M a))
    -> ReadS [M a] -> ReadPrec (M a) -> ReadPrec [M a] -> Read (M a)
    forall a. Read a => ReadPrec [M a]
    forall a. Read a => ReadPrec (M a)
    forall a. Read a => Int -> ReadS (M a)
    forall a. Read a => ReadS [M a]
    forall a.
    (Int -> ReadS a)
    -> ReadS [a] -> ReadPrec a -> ReadPrec [a] -> Read a
    readListPrec :: ReadPrec [M a]
    $creadListPrec :: forall a. Read a => ReadPrec [M a]
    readPrec :: ReadPrec (M a)
    $creadPrec :: forall a. Read a => ReadPrec (M a)
    readList :: ReadS [M a]
    $creadList :: forall a. Read a => ReadS [M a]
    readsPrec :: Int -> ReadS (M a)
    $creadsPrec :: forall a. Read a => Int -> ReadS (M a)
    Read, a -> M b -> M a
    (a -> b) -> M a -> M b
    (forall a b. (a -> b) -> M a -> M b)
    -> (forall a b. a -> M b -> M a) -> Functor M
    forall a b. a -> M b -> M a
    forall a b. (a -> b) -> M a -> M b
    forall (f :: * -> *).
    (forall a b. (a -> b) -> f a -> f b)
    -> (forall a b. a -> f b -> f a) -> Functor f
    <$ :: a -> M b -> M a
    $c<$ :: forall a b. a -> M b -> M a
    fmap :: (a -> b) -> M a -> M b
    $cfmap :: forall a b. (a -> b) -> M a -> M b
    Functor, M a -> Bool
    (a -> m) -> M a -> m
    (a -> b -> b) -> b -> M a -> b
    (forall m. Monoid m => M m -> m)
    -> (forall m a. Monoid m => (a -> m) -> M a -> m)
    -> (forall m a. Monoid m => (a -> m) -> M a -> m)
    -> (forall a b. (a -> b -> b) -> b -> M a -> b)
    -> (forall a b. (a -> b -> b) -> b -> M a -> b)
    -> (forall b a. (b -> a -> b) -> b -> M a -> b)
    -> (forall b a. (b -> a -> b) -> b -> M a -> b)
    -> (forall a. (a -> a -> a) -> M a -> a)
    -> (forall a. (a -> a -> a) -> M a -> a)
    -> (forall a. M a -> [a])
    -> (forall a. M a -> Bool)
    -> (forall a. M a -> Int)
    -> (forall a. Eq a => a -> M a -> Bool)
    -> (forall a. Ord a => M a -> a)
    -> (forall a. Ord a => M a -> a)
    -> (forall a. Num a => M a -> a)
    -> (forall a. Num a => M a -> a)
    -> Foldable M
    forall a. Eq a => a -> M a -> Bool
    forall a. Num a => M a -> a
    forall a. Ord a => M a -> a
    forall m. Monoid m => M m -> m
    forall a. M a -> Bool
    forall a. M a -> Int
    forall a. M a -> [a]
    forall a. (a -> a -> a) -> M a -> a
    forall m a. Monoid m => (a -> m) -> M a -> m
    forall b a. (b -> a -> b) -> b -> M a -> b
    forall a b. (a -> b -> b) -> b -> M a -> b
    forall (t :: * -> *).
    (forall m. Monoid m => t m -> m)
    -> (forall m a. Monoid m => (a -> m) -> t a -> m)
    -> (forall m a. Monoid m => (a -> m) -> t a -> m)
    -> (forall a b. (a -> b -> b) -> b -> t a -> b)
    -> (forall a b. (a -> b -> b) -> b -> t a -> b)
    -> (forall b a. (b -> a -> b) -> b -> t a -> b)
    -> (forall b a. (b -> a -> b) -> b -> t a -> b)
    -> (forall a. (a -> a -> a) -> t a -> a)
    -> (forall a. (a -> a -> a) -> t a -> a)
    -> (forall a. t a -> [a])
    -> (forall a. t a -> Bool)
    -> (forall a. t a -> Int)
    -> (forall a. Eq a => a -> t a -> Bool)
    -> (forall a. Ord a => t a -> a)
    -> (forall a. Ord a => t a -> a)
    -> (forall a. Num a => t a -> a)
    -> (forall a. Num a => t a -> a)
    -> Foldable t
    product :: M a -> a
    $cproduct :: forall a. Num a => M a -> a
    sum :: M a -> a
    $csum :: forall a. Num a => M a -> a
    minimum :: M a -> a
    $cminimum :: forall a. Ord a => M a -> a
    maximum :: M a -> a
    $cmaximum :: forall a. Ord a => M a -> a
    elem :: a -> M a -> Bool
    $celem :: forall a. Eq a => a -> M a -> Bool
    length :: M a -> Int
    $clength :: forall a. M a -> Int
    null :: M a -> Bool
    $cnull :: forall a. M a -> Bool
    toList :: M a -> [a]
    $ctoList :: forall a. M a -> [a]
    foldl1 :: (a -> a -> a) -> M a -> a
    $cfoldl1 :: forall a. (a -> a -> a) -> M a -> a
    foldr1 :: (a -> a -> a) -> M a -> a
    $cfoldr1 :: forall a. (a -> a -> a) -> M a -> a
    foldl' :: (b -> a -> b) -> b -> M a -> b
    $cfoldl' :: forall b a. (b -> a -> b) -> b -> M a -> b
    foldl :: (b -> a -> b) -> b -> M a -> b
    $cfoldl :: forall b a. (b -> a -> b) -> b -> M a -> b
    foldr' :: (a -> b -> b) -> b -> M a -> b
    $cfoldr' :: forall a b. (a -> b -> b) -> b -> M a -> b
    foldr :: (a -> b -> b) -> b -> M a -> b
    $cfoldr :: forall a b. (a -> b -> b) -> b -> M a -> b
    foldMap' :: (a -> m) -> M a -> m
    $cfoldMap' :: forall m a. Monoid m => (a -> m) -> M a -> m
    foldMap :: (a -> m) -> M a -> m
    $cfoldMap :: forall m a. Monoid m => (a -> m) -> M a -> m
    fold :: M m -> m
    $cfold :: forall m. Monoid m => M m -> m
    Foldable, Functor M
    Foldable M
    (Functor M, Foldable M) =>
    (forall (f :: * -> *) a b.
     Applicative f =>
     (a -> f b) -> M a -> f (M b))
    -> (forall (f :: * -> *) a. Applicative f => M (f a) -> f (M a))
    -> (forall (m :: * -> *) a b.
        Monad m =>
        (a -> m b) -> M a -> m (M b))
    -> (forall (m :: * -> *) a. Monad m => M (m a) -> m (M a))
    -> Traversable M
    (a -> f b) -> M a -> f (M b)
    forall (t :: * -> *).
    (Functor t, Foldable t) =>
    (forall (f :: * -> *) a b.
     Applicative f =>
     (a -> f b) -> t a -> f (t b))
    -> (forall (f :: * -> *) a. Applicative f => t (f a) -> f (t a))
    -> (forall (m :: * -> *) a b.
        Monad m =>
        (a -> m b) -> t a -> m (t b))
    -> (forall (m :: * -> *) a. Monad m => t (m a) -> m (t a))
    -> Traversable t
    forall (m :: * -> *) a. Monad m => M (m a) -> m (M a)
    forall (f :: * -> *) a. Applicative f => M (f a) -> f (M a)
    forall (m :: * -> *) a b. Monad m => (a -> m b) -> M a -> m (M b)
    forall (f :: * -> *) a b.
    Applicative f =>
    (a -> f b) -> M a -> f (M b)
    sequence :: M (m a) -> m (M a)
    $csequence :: forall (m :: * -> *) a. Monad m => M (m a) -> m (M a)
    mapM :: (a -> m b) -> M a -> m (M b)
    $cmapM :: forall (m :: * -> *) a b. Monad m => (a -> m b) -> M a -> m (M b)
    sequenceA :: M (f a) -> f (M a)
    $csequenceA :: forall (f :: * -> *) a. Applicative f => M (f a) -> f (M a)
    traverse :: (a -> f b) -> M a -> f (M b)
    $ctraverse :: forall (f :: * -> *) a b.
    Applicative f =>
    (a -> f b) -> M a -> f (M b)
    $cp2Traversable :: Foldable M
    $cp1Traversable :: Functor M
    Traversable, Typeable)
    {-# DEPRECATED M "Use aeson-1 TOJSONKey etc functionality" #-}

    class FromJSONKey a where
      parseJSONKey :: Text -> Parser a

    instance FromJSONKey Text where parseJSONKey :: Text -> Parser Text
    parseJSONKey = Text -> Parser Text
    forall (f :: * -> *) a. Applicative f => a -> f a
    pure
    instance FromJSONKey LT.Text where parseJSONKey :: Text -> Parser Text
    parseJSONKey = Text -> Parser Text
    forall (f :: * -> *) a. Applicative f => a -> f a
    pure (Text -> Parser Text) -> (Text -> Text) -> Text -> Parser Text
    forall b c a. (b -> c) -> (a -> b) -> a -> c
    . Text -> Text
    LT.fromStrict
    instance FromJSONKey String where parseJSONKey :: Text -> Parser String
    parseJSONKey = String -> Parser String
    forall (f :: * -> *) a. Applicative f => a -> f a
    pure (String -> Parser String)
    -> (Text -> String) -> Text -> Parser String
    forall b c a. (b -> c) -> (a -> b) -> a -> c
    . Text -> String
    T.unpack
    instance FromJSONKey Int where parseJSONKey :: Text -> Parser Int
    parseJSONKey = Text -> Parser Int
    forall a. Integral a => Text -> Parser a
    parseIntegralJSONKey
    instance FromJSONKey Integer where parseJSONKey :: Text -> Parser Integer
    parseJSONKey = Text -> Parser Integer
    forall a. Integral a => Text -> Parser a
    parseIntegralJSONKey

    parseIntegralJSONKey :: Integral a => Text -> Parser a
    parseIntegralJSONKey :: Text -> Parser a
    parseIntegralJSONKey t :: Text
    t = case Reader a -> Reader a
    forall a. Num a => Reader a -> Reader a
    T.signed Reader a
    forall a. Integral a => Reader a
    T.decimal Text
    t of
      Right (v :: a
    v, left :: Text
    left) | Text -> Bool
    T.null Text
    left  -> a -> Parser a
    forall (f :: * -> *) a. Applicative f => a -> f a
    pure a
    v
                      | Bool
    otherwise    -> String -> Parser a
    forall (m :: * -> *) a. MonadFail m => String -> m a
    fail (String -> Parser a) -> String -> Parser a
    forall a b. (a -> b) -> a -> b
    $ "Garbage left: " String -> ShowS
    forall a. Semigroup a => a -> a -> a
    <> Text -> String
    T.unpack Text
    left
      Left err :: String
    err                       -> String -> Parser a
    forall (m :: * -> *) a. MonadFail m => String -> m a
    fail String
    err

    class FromJSONMap m k v | m -> k v where
      parseJSONMap :: HM.HashMap Text Value -> Parser m

    instance (Eq k, Hashable k, FromJSONKey k, FromJSON v) => FromJSONMap (HM.HashMap k v) k v where
      parseJSONMap :: HashMap Text Value -> Parser (HashMap k v)
    parseJSONMap = ([(k, v)] -> HashMap k v)
    -> Parser [(k, v)] -> Parser (HashMap k v)
    forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
    fmap [(k, v)] -> HashMap k v
    forall k v. (Eq k, Hashable k) => [(k, v)] -> HashMap k v
    HM.fromList (Parser [(k, v)] -> Parser (HashMap k v))
    -> (HashMap Text Value -> Parser [(k, v)])
    -> HashMap Text Value
    -> Parser (HashMap k v)
    forall b c a. (b -> c) -> (a -> b) -> a -> c
    . ((Text, Value) -> Parser (k, v))
    -> [(Text, Value)] -> Parser [(k, v)]
    forall (t :: * -> *) (f :: * -> *) a b.
    (Traversable t, Applicative f) =>
    (a -> f b) -> t a -> f (t b)
    traverse (Text, Value) -> Parser (k, v)
    forall a a.
    (FromJSONKey a, FromJSON a) =>
    (Text, Value) -> Parser (a, a)
    f ([(Text, Value)] -> Parser [(k, v)])
    -> (HashMap Text Value -> [(Text, Value)])
    -> HashMap Text Value
    -> Parser [(k, v)]
    forall b c a. (b -> c) -> (a -> b) -> a -> c
    . HashMap Text Value -> [(Text, Value)]
    forall k v. HashMap k v -> [(k, v)]
    HM.toList
        where f :: (Text, Value) -> Parser (a, a)
    f (k :: Text
    k, v :: Value
    v) = (,) (a -> a -> (a, a)) -> Parser a -> Parser (a -> (a, a))
    forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
    <$> Text -> Parser a
    forall a. FromJSONKey a => Text -> Parser a
    parseJSONKey Text
    k Parser (a -> (a, a)) -> Parser a -> Parser (a, a)
    forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
    <*> Value -> Parser a
    forall a. FromJSON a => Value -> Parser a
    parseJSON Value
    v

    instance (Ord k, FromJSONKey k, FromJSON v) => FromJSONMap (Map.Map k v) k v where
      parseJSONMap :: HashMap Text Value -> Parser (Map k v)
    parseJSONMap = ([(k, v)] -> Map k v) -> Parser [(k, v)] -> Parser (Map k v)
    forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
    fmap [(k, v)] -> Map k v
    forall k a. Ord k => [(k, a)] -> Map k a
    Map.fromList (Parser [(k, v)] -> Parser (Map k v))
    -> (HashMap Text Value -> Parser [(k, v)])
    -> HashMap Text Value
    -> Parser (Map k v)
    forall b c a. (b -> c) -> (a -> b) -> a -> c
    . ((Text, Value) -> Parser (k, v))
    -> [(Text, Value)] -> Parser [(k, v)]
    forall (t :: * -> *) (f :: * -> *) a b.
    (Traversable t, Applicative f) =>
    (a -> f b) -> t a -> f (t b)
    traverse (Text, Value) -> Parser (k, v)
    forall a a.
    (FromJSONKey a, FromJSON a) =>
    (Text, Value) -> Parser (a, a)
    f ([(Text, Value)] -> Parser [(k, v)])
    -> (HashMap Text Value -> [(Text, Value)])
    -> HashMap Text Value
    -> Parser [(k, v)]
    forall b c a. (b -> c) -> (a -> b) -> a -> c
    . HashMap Text Value -> [(Text, Value)]
    forall k v. HashMap k v -> [(k, v)]
    HM.toList
        where f :: (Text, Value) -> Parser (a, a)
    f (k :: Text
    k, v :: Value
    v) = (,) (a -> a -> (a, a)) -> Parser a -> Parser (a -> (a, a))
    forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
    <$> Text -> Parser a
    forall a. FromJSONKey a => Text -> Parser a
    parseJSONKey Text
    k Parser (a -> (a, a)) -> Parser a -> Parser (a, a)
    forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
    <*> Value -> Parser a
    forall a. FromJSON a => Value -> Parser a
    parseJSON Value
    v

    instance (FromJSONMap m k v) => FromJSON (M m) where
      parseJSON :: Value -> Parser (M m)
    parseJSON v :: Value
    v = m -> M m
    forall a. a -> M a
    M (m -> M m) -> Parser m -> Parser (M m)
    forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
    <$> String -> (HashMap Text Value -> Parser m) -> Value -> Parser m
    forall a.
    String -> (HashMap Text Value -> Parser a) -> Value -> Parser a
    withObject "Map" HashMap Text Value -> Parser m
    forall m k v. FromJSONMap m k v => HashMap Text Value -> Parser m
    parseJSONMap Value
    v

    class ToJSONKey a where
      toJSONKey :: a -> Text

    instance ToJSONKey Text where toJSONKey :: Text -> Text
    toJSONKey = Text -> Text
    forall a. a -> a
    id
    instance ToJSONKey LT.Text where toJSONKey :: Text -> Text
    toJSONKey = Text -> Text
    LT.toStrict
    instance ToJSONKey String where toJSONKey :: String -> Text
    toJSONKey = String -> Text
    T.pack
    instance ToJSONKey Int where toJSONKey :: Int -> Text
    toJSONKey = String -> Text
    T.pack (String -> Text) -> (Int -> String) -> Int -> Text
    forall b c a. (b -> c) -> (a -> b) -> a -> c
    . Int -> String
    forall a. Show a => a -> String
    show
    instance ToJSONKey Integer where toJSONKey :: Integer -> Text
    toJSONKey = String -> Text
    T.pack (String -> Text) -> (Integer -> String) -> Integer -> Text
    forall b c a. (b -> c) -> (a -> b) -> a -> c
    . Integer -> String
    forall a. Show a => a -> String
    show

    class ToJSONMap m k v | m -> k v where
      toJSONMap :: m -> HM.HashMap Text Value

    instance (ToJSONKey k, ToJSON v) => ToJSONMap (HM.HashMap k v) k v where
      toJSONMap :: HashMap k v -> HashMap Text Value
    toJSONMap = [(Text, Value)] -> HashMap Text Value
    forall k v. (Eq k, Hashable k) => [(k, v)] -> HashMap k v
    HM.fromList ([(Text, Value)] -> HashMap Text Value)
    -> (HashMap k v -> [(Text, Value)])
    -> HashMap k v
    -> HashMap Text Value
    forall b c a. (b -> c) -> (a -> b) -> a -> c
    . ((k, v) -> (Text, Value)) -> [(k, v)] -> [(Text, Value)]
    forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
    fmap (k, v) -> (Text, Value)
    forall a a. (ToJSONKey a, ToJSON a) => (a, a) -> (Text, Value)
    f ([(k, v)] -> [(Text, Value)])
    -> (HashMap k v -> [(k, v)]) -> HashMap k v -> [(Text, Value)]
    forall b c a. (b -> c) -> (a -> b) -> a -> c
    . HashMap k v -> [(k, v)]
    forall k v. HashMap k v -> [(k, v)]
    HM.toList
        where f :: (a, a) -> (Text, Value)
    f (k :: a
    k, v :: a
    v) = (a -> Text
    forall a. ToJSONKey a => a -> Text
    toJSONKey a
    k, a -> Value
    forall a. ToJSON a => a -> Value
    toJSON a
    v)

    instance (ToJSONKey k, ToJSON v) => ToJSONMap (Map.Map k v) k v where
      toJSONMap :: Map k v -> HashMap Text Value
    toJSONMap = [(Text, Value)] -> HashMap Text Value
    forall k v. (Eq k, Hashable k) => [(k, v)] -> HashMap k v
    HM.fromList ([(Text, Value)] -> HashMap Text Value)
    -> (Map k v -> [(Text, Value)]) -> Map k v -> HashMap Text Value
    forall b c a. (b -> c) -> (a -> b) -> a -> c
    . ((k, v) -> (Text, Value)) -> [(k, v)] -> [(Text, Value)]
    forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
    fmap (k, v) -> (Text, Value)
    forall a a. (ToJSONKey a, ToJSON a) => (a, a) -> (Text, Value)
    f ([(k, v)] -> [(Text, Value)])
    -> (Map k v -> [(k, v)]) -> Map k v -> [(Text, Value)]
    forall b c a. (b -> c) -> (a -> b) -> a -> c
    . Map k v -> [(k, v)]
    forall k a. Map k a -> [(k, a)]
    Map.toList
        where f :: (a, a) -> (Text, Value)
    f (k :: a
    k, v :: a
    v) = (a -> Text
    forall a. ToJSONKey a => a -> Text
    toJSONKey a
    k, a -> Value
    forall a. ToJSON a => a -> Value
    toJSON a
    v)

    instance (ToJSONMap m k v) => ToJSON (M m) where
      toJSON :: M m -> Value
    toJSON (M m :: m
    m) = HashMap Text Value -> Value
    Object (m -> HashMap Text Value
    forall m k v. ToJSONMap m k v => m -> HashMap Text Value
    toJSONMap m
    m)