This is a stupid question, and I have tried to understand from different tutorials. When having a JSON with capital case Haskell crashes as explained by others (https://mail.haskell.org/pipermail/beginners/2013-October/012865.html). As suggested it could be solved with deriving from deriveFromJSON. DeriveJSON requires a function input, how should I write the derive statement in the below code? I am missing something in my understanding, and would appreciate any help.
import Data.Aeson.TH
data Person = Person {
Foo :: String
, bar :: String
} deriving (Eq, Show, deriveJSON)
main = do
let b = Person "t" "x"
print b
deriveJSON
and friends are Template Haskell functions which will generate instances for you. As such, you should not try to list them in thederiving
clause. Instead, call them in a splice at the top level like this:As mentioned in the mailing list, you can customize the field names by overriding the
fieldLabelModifier
function of thedefaultOptions
record, for example this will change the JSON name offoo
toFoo
: