Say I have type Person
import GHC.Generics import Data.Text import Data.Aeson import Control.Lens data Person = Person { _firstName :: Text, _lastName :: Text, _age :: Int } deriving (Show, Generic)
And I want to automatically output lenses and JSON types for it for
makeLenses ''Person instance FromJSON Person instance ToJSON Person
This works correctly, however DeriveGeneric sees that my field names have an underscore and expects my JSON to be formatted accordingly.
{ "_firstName": "James" ... etc} -- The underscore doesn't belong here.
Obviously, I could remove the underline from the data definition itself, but then makeLenses could not get the necessary getters and setters.
Ideally, what I want to do is something like this
let person = decode blob let name = person ^. firstName
i.e. I want to get lenses and JSON instances with all field names that correctly match the values ββin the Api JSON-REST that I consume, without having to write a lot of templates.
It seems like such a direct thing that I feel like I'm missing something obvious?
source share