@@ -46,6 +46,14 @@ import GHC.TypeLits
4646import qualified Optics.Lens as OL
4747import Unsafe.Coerce
4848import Prelude
49+#if MIN_VERSION_aeson(2,0,0)
50+import Data.Aeson.Key (fromText, fromString)
51+#else
52+fromText :: a -> a
53+fromText = id
54+fromString :: String -> T.Text
55+fromString = T.pack
56+#endif
4957
5058-- | Field named @l@ labels value of type @t@ adapted from the awesome /labels/ package.
5159-- Example: @(#name := \"Chris\") :: (\"name\" := String)@
@@ -558,16 +566,16 @@ class ToJSON a => EncodeField a where
558566
559567instance ToJSON a => EncodeField a where
560568 encodeField = pure . toJSON
561− encodeKV = (.=)
569+ encodeKV k v = fromText k .= v
562570
563571instance {-# OVERLAPS #-} ToJSON a => EncodeField (Maybe a) where
564572 encodeField = fmap toJSON
565573 encodeKV _ Nothing = mempty
566− encodeKV k v = k .= v
574+ encodeKV k v = fromText k .= v
567575
568576recToValue :: forall lts. (RecApply lts lts EncodeField) => JSONOptions -> Rec lts -> Value
569577recToValue options r =
570− object $ catMaybes $ reflectRec @EncodeField Proxy (\k v -> (T.pack (fieldTransform options k),) <$> encodeField v) r
578+ object $ catMaybes $ reflectRec @EncodeField Proxy (\k v -> (fromString (fieldTransform options k),) <$> encodeField v) r
571579
572580recToEncoding :: forall lts. (RecApply lts lts EncodeField) => JSONOptions -> Rec lts -> Encoding
573581recToEncoding options r =
@@ -672,10 +680,10 @@ class FromJSON a => ParseField a where
672680 parseField :: Object -> T.Text -> Parser a
673681
674682instance FromJSON a => ParseField a where
675− parseField = (.:)
683+ parseField o k = o .: fromText k
676684
677685instance {-# OVERLAPS #-} FromJSON a => ParseField (Maybe a) where
678− parseField = (.:?)
686+ parseField o k = o .:? fromText k
679687
680688instance
681689 ( KnownSymbol l,