{"action":"closed","issue":{"url":"https://api.github.com/repos/purescript-contrib/purescript-argonaut-codecs/issues/5","repository_url":"https://api.github.com/repos/purescript-contrib/purescript-argonaut-codecs","labels_url":"https://api.github.com/repos/purescript-contrib/purescript-argonaut-codecs/issues/5/labels{/name}","comments_url":"https://api.github.com/repos/purescript-contrib/purescript-argonaut-codecs/issues/5/comments","events_url":"https://api.github.com/repos/purescript-contrib/purescript-argonaut-codecs/issues/5/events","html_url":"https://github.com/purescript-contrib/purescript-argonaut-codecs/issues/5","id":112944054,"number":5,"title":"easily encode/decode records","user":{"login":"cdepillabout","id":64804,"avatar_url":"https://avatars.githubusercontent.com/u/64804?v=3","gravatar_id":"","url":"https://api.github.com/users/cdepillabout","html_url":"https://github.com/cdepillabout","followers_url":"https://api.github.com/users/cdepillabout/followers","following_url":"https://api.github.com/users/cdepillabout/following{/other_user}","gists_url":"https://api.github.com/users/cdepillabout/gists{/gist_id}","starred_url":"https://api.github.com/users/cdepillabout/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/cdepillabout/subscriptions","organizations_url":"https://api.github.com/users/cdepillabout/orgs","repos_url":"https://api.github.com/users/cdepillabout/repos","events_url":"https://api.github.com/users/cdepillabout/events{/privacy}","received_events_url":"https://api.github.com/users/cdepillabout/received_events","type":"User","site_admin":false},"labels":[],"state":"closed","locked":false,"assignee":null,"assignees":[],"milestone":null,"comments":8,"created_at":"2015-10-23T03:48:53Z","updated_at":"2016-08-06T00:45:33Z","closed_at":"2016-08-06T00:45:33Z","body":"Is there a way to easily encode and decode records?\r\n\r\nFor instance, I have the following type:\r\n\r\n```\r\nnewtype Register = Register { email :: String\r\n                            , password :: String\r\n                            }\r\n```\r\n\r\nI'd like to use purescript-generics for the encoding and decoding like below:\r\n\r\n```\r\nderive instance genericRegister :: Generic Register\r\ninstance encodeJsonRegister :: EncodeJson Register where\r\n    encodeJson = gEncodeJson\r\n```\r\n\r\nBut when running the following code:\r\n```\r\nlet register = Register { email: \"email@email.com\", password: \"foobar\" }\r\nin show $ encodeJson res\r\n```\r\nI get the following output: `{\"values\":[{\"password\":\"foobar\",\"email\":\"email@email.com\"}],\"tag\":\"Register\"}`\r\nI was expecting the output to look like this: `{\"password\":\"foobar\",\"email\":\"email@email.com\"}`\r\n\r\nI tried to change the EncodeJson instance like the following:\r\n```\r\ninstance encodeJsonRegister :: EncodeJson Register where\r\n    encodeJson (Register reg) = gEncodeJson reg\r\n```\r\nBut that just gave me the following compiler error:\r\n```\r\nError found:\r\nError in value declaration encodeJsonRegister:\r\nError at /opt/src/src/Main.purs line 44, column 1 - line 46, column 1:\r\nError in module Main:\r\nNo instance found for\r\n\r\n  Data.Generic.Generic { password :: String\r\n                       , email :: String\r\n                       }\r\n```\r\n\r\nThe error makes sense, but I was hoping it would be easier to define `encodeJson` for records.  Is there an easy way?  I don't want to have to write out something like this for every type:\r\n```\r\n  instance encodeJsonRegister :: EncodeJson Register where\r\n    encodeJson (Register reg)\r\n      =  \"email\" := reg.email\r\n      ~> \"password\" := reg.password\r\n      ~> jsonEmptyObject\r\n```\r\n\r\nMaybe I've just been spoiled by `aeson` :-("}}
{"actor":{"display_login":"cdepillabout"}}