3 ms·
Yes, smooth sailing in Haskell. Define the datatype and let GHC generics and the Aeson library handle the rest. The worst-case scenario is when keys in your J
by mrkeen 6y ago
Yes, smooth sailing in Haskell.
Define the datatype and let GHC generics and the Aeson library handle the rest.
The worst-case scenario is when keys in your JSON conflict with keywords or existing functions: 'id' and 'data' are pretty common. It means you need to rename your datatype fields to something like '_id' and '_data', and provide a mapping function to Aeson.
Where the 'fully automatic' declaration looks like:
instance FromJSON Coord
The declaration where you remap to avoid name clashes could look like:
instance FromJSON Coord where
parseJSON = genericParseJSON defaultOptions { fieldLabelModifier = dropWhile (=='_') }