@@ -39,6 +39,7 @@ module Data.Aeson.Types.ToJSON
39
39
, ToJSONKey (.. )
40
40
, ToJSONKeyFunction (.. )
41
41
, toJSONKeyText
42
+ , toJSONKeyKey
42
43
, contramapToJSONKeyFunction
43
44
44
45
, GToJSONKey ()
@@ -490,8 +491,14 @@ data ToJSONKeyFunction a
490
491
-- where
491
492
-- myKeyToText = Text.pack . show -- or showt from text-show
492
493
-- @
493
- toJSONKeyText :: (a -> Key ) -> ToJSONKeyFunction a
494
- toJSONKeyText f = ToJSONKeyText f (E. key . f)
494
+ toJSONKeyText :: (a -> Text ) -> ToJSONKeyFunction a
495
+ toJSONKeyText f = toJSONKeyKey (Key. fromText . f)
496
+
497
+ -- |
498
+ --
499
+ -- @since 2.0.0.0
500
+ toJSONKeyKey :: (a -> Key ) -> ToJSONKeyFunction a
501
+ toJSONKeyKey f = ToJSONKeyText f (E. key . f)
495
502
496
503
-- | TODO: should this be exported?
497
504
toJSONKeyTextEnc :: (a -> Encoding' Key ) -> ToJSONKeyFunction a
@@ -532,7 +539,7 @@ contramapToJSONKeyFunction h x = case x of
532
539
-- @
533
540
genericToJSONKey :: (Generic a , GToJSONKey (Rep a ))
534
541
=> JSONKeyOptions -> ToJSONKeyFunction a
535
- genericToJSONKey opts = toJSONKeyText (Key. fromString . keyModifier opts . getConName . from)
542
+ genericToJSONKey opts = toJSONKeyKey (Key. fromString . keyModifier opts . getConName . from)
536
543
537
544
class GetConName f => GToJSONKey f
538
545
instance GetConName f => GToJSONKey f
@@ -1448,23 +1455,23 @@ instance ToJSON Text where
1448
1455
toEncoding = E. text
1449
1456
1450
1457
instance ToJSONKey Text where
1451
- toJSONKey = toJSONKeyText Key. fromText
1458
+ toJSONKey = toJSONKeyText id
1452
1459
1453
1460
1454
1461
instance ToJSON LT. Text where
1455
1462
toJSON = String . LT. toStrict
1456
1463
toEncoding = E. lazyText
1457
1464
1458
1465
instance ToJSONKey LT. Text where
1459
- toJSONKey = toJSONKeyText (Key. fromText . LT. toStrict)
1466
+ toJSONKey = toJSONKeyText (LT. toStrict)
1460
1467
1461
1468
1462
1469
instance ToJSON Version where
1463
1470
toJSON = toJSON . showVersion
1464
1471
toEncoding = toEncoding . showVersion
1465
1472
1466
1473
instance ToJSONKey Version where
1467
- toJSONKey = toJSONKeyText (Key. fromString . showVersion)
1474
+ toJSONKey = toJSONKeyKey (Key. fromString . showVersion)
1468
1475
1469
1476
-------------------------------------------------------------------------------
1470
1477
-- semigroups NonEmpty
@@ -2199,8 +2206,8 @@ instance (ToJSON a, ToJSON b, ToJSON c) => ToJSONKey (a,b,c)
2199
2206
instance (ToJSON a , ToJSON b , ToJSON c , ToJSON d ) => ToJSONKey (a ,b ,c ,d )
2200
2207
2201
2208
instance ToJSONKey Char where
2202
- toJSONKey = ToJSONKeyText ( Key. fromText . T. singleton) ( E. key . Key. fromText . T. singleton)
2203
- toJSONKeyList = toJSONKeyText Key. fromString
2209
+ toJSONKey = toJSONKeyText T. singleton
2210
+ toJSONKeyList = toJSONKeyText T. pack
2204
2211
2205
2212
instance (ToJSONKey a , ToJSON a ) => ToJSONKey [a ] where
2206
2213
toJSONKey = toJSONKeyList
0 commit comments