@@ -43,11 +43,17 @@ import GHC.OverloadedLabels
4343import GHC.Prim
4444import GHC.ST (ST (..), runST)
4545import GHC.TypeLits
46−import Generic.Data (gshowsPrec)
47−import Generic.Data.Internal.Show (GShow)
4846import qualified Optics.Lens as OL
4947import Unsafe.Coerce
5048import 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
5157
5258-- | Field named @l@ labels value of type @t@ adapted from the awesome /labels/ package.
5359-- Example: @(#name := \"Chris\") :: (\"name\" := String)@
@@ -560,16 +566,16 @@ class ToJSON a => EncodeField a where
560566
561567instance ToJSON a => EncodeField a where
562568 encodeField = pure . toJSON
563− encodeKV = (.=)
569+ encodeKV k v = fromText k .= v
564570
565571instance {-# OVERLAPS #-} ToJSON a => EncodeField (Maybe a) where
566572 encodeField = fmap toJSON
567573 encodeKV _ Nothing = mempty
568− encodeKV k v = k .= v
574+ encodeKV k v = fromText k .= v
569575
570576recToValue :: forall lts. (RecApply lts lts EncodeField) => JSONOptions -> Rec lts -> Value
571577recToValue options r =
572− 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
573579
574580recToEncoding :: forall lts. (RecApply lts lts EncodeField) => JSONOptions -> Rec lts -> Encoding
575581recToEncoding options r =
@@ -674,10 +680,10 @@ class FromJSON a => ParseField a where
674680 parseField :: Object -> T.Text -> Parser a
675681
676682instance FromJSON a => ParseField a where
677− parseField = (.:)
683+ parseField o k = o .: fromText k
678684
679685instance {-# OVERLAPS #-} FromJSON a => ParseField (Maybe a) where
680− parseField = (.:?)
686+ parseField o k = o .:? fromText k
681687
682688instance
683689 ( KnownSymbol l,