{"action":"created","issue":{"url":"https://api.github.com/repos/bos/aeson/issues/357","repository_url":"https://api.github.com/repos/bos/aeson","labels_url":"https://api.github.com/repos/bos/aeson/issues/357/labels{/name}","comments_url":"https://api.github.com/repos/bos/aeson/issues/357/comments","events_url":"https://api.github.com/repos/bos/aeson/issues/357/events","html_url":"https://github.com/bos/aeson/issues/357","id":131919058,"number":357,"title":"JSONPath isn't tracked in autoderived instances","user":{"login":"neongreen","id":1523306,"avatar_url":"https://avatars.githubusercontent.com/u/1523306?v=3","gravatar_id":"","url":"https://api.github.com/users/neongreen","html_url":"https://github.com/neongreen","followers_url":"https://api.github.com/users/neongreen/followers","following_url":"https://api.github.com/users/neongreen/following{/other_user}","gists_url":"https://api.github.com/users/neongreen/gists{/gist_id}","starred_url":"https://api.github.com/users/neongreen/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/neongreen/subscriptions","organizations_url":"https://api.github.com/users/neongreen/orgs","repos_url":"https://api.github.com/users/neongreen/repos","events_url":"https://api.github.com/users/neongreen/events{/privacy}","received_events_url":"https://api.github.com/users/neongreen/received_events","type":"User","site_admin":false},"labels":[{"url":"https://api.github.com/repos/bos/aeson/labels/bug","name":"bug","color":"e11d21"}],"state":"open","locked":false,"assignee":null,"milestone":null,"comments":2,"created_at":"2016-02-07T01:00:16Z","updated_at":"2016-02-08T00:31:05Z","closed_at":null,"body":"Let's create a type and derive an instance for it.\r\n\r\nWith TH:\r\n\r\n~~~ haskell\r\n{-# LANGUAGE TemplateHaskell #-}\r\n\r\nimport Data.Aeson\r\nimport Data.Aeson.TH\r\n\r\ndata X = X {a :: (Int, Int, Int)} \r\n  deriving Show\r\n\r\nderiveJSON defaultOptions ''X\r\n~~~\r\n\r\nOr with generics:\r\n\r\n~~~ haskell\r\n{-# LANGUAGE DeriveGeneric #-}\r\n\r\nimport Data.Aeson\r\n\r\ndata X = X {a :: (Int, Int, Int)}\r\n  deriving (Show, Generic)\r\n\r\ninstance FromJSON X where\r\n  parseJSON = genericParseJSON defaultOptions \r\n~~~\r\n\r\nThen try to decode an invalid value:\r\n\r\n~~~\r\n> eitherDecode \"{\\\"a\\\": [1, 2, true]}\" :: Either String X\r\nLeft \"Error in $[2]: expected Int, encountered Boolean\"\r\n~~~\r\n\r\nI believe it should be `$.a[2]`.\r\n\r\n(I checked with latest Aeson from the repository, commit 2f0b989.)"},"comment":{"url":"https://api.github.com/repos/bos/aeson/issues/comments/181146302","html_url":"https://github.com/bos/aeson/issues/357#issuecomment-181146302","issue_url":"https://api.github.com/repos/bos/aeson/issues/357","id":181146302,"user":{"login":"neongreen","id":1523306,"avatar_url":"https://avatars.githubusercontent.com/u/1523306?v=3","gravatar_id":"","url":"https://api.github.com/users/neongreen","html_url":"https://github.com/neongreen","followers_url":"https://api.github.com/users/neongreen/followers","following_url":"https://api.github.com/users/neongreen/following{/other_user}","gists_url":"https://api.github.com/users/neongreen/gists{/gist_id}","starred_url":"https://api.github.com/users/neongreen/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/neongreen/subscriptions","organizations_url":"https://api.github.com/users/neongreen/orgs","repos_url":"https://api.github.com/users/neongreen/repos","events_url":"https://api.github.com/users/neongreen/events{/privacy}","received_events_url":"https://api.github.com/users/neongreen/received_events","type":"User","site_admin":false},"created_at":"2016-02-08T00:31:05Z","updated_at":"2016-02-08T00:31:05Z","body":"Relevant code in `Data.Aeson.TH` is here: https://github.com/bos/aeson/blob/master/Data/Aeson/TH.hs#L992. For some reason it uses a manual `lookup` instead of `.:`:\r\n\r\n~~~ haskell\r\n    lookupField tName rec obj key =\r\n        case H.lookup key obj of\r\n          Nothing -> unknownFieldFail tName rec (T.unpack key)\r\n          Just v  -> parseJSON v\r\n~~~\r\n\r\nI'm not sure where the code for generics is, but it's probably here: <https://github.com/bos/aeson/blob/master/Data/Aeson/Types/Generic.hs#L670>:\r\n\r\n~~~ haskell\r\ninstance (Selector s, GFromJSON a) => FromRecord (S1 s a) where\r\n    parseRecord opts (Just lab) = maybe (notFound $ unpack lab)\r\n                      (gParseJSON opts) . H.lookup lab\r\n    parseRecord opts Nothing    = maybe (notFound label)\r\n                      (gParseJSON opts) . H.lookup (pack label)\r\n        where\r\n          label = fieldLabelModifier opts $ selName (undefined :: t s a p)\r\n~~~\r\n\r\n(It's the only place in `Data.Aeson.Types.Generic` where `lookup` is mentioned.)"}}