agrafix / superrecord

Haskell: Supercharged anonymous records
BSD 3-Clause "New" or "Revised" License
83 stars 16 forks source link

Use objects for ToJSON/FromJSON instances #7

Closed neongreen closed 7 years ago

neongreen commented 7 years ago

Currently records are converted into arrays of pairs:

> toJSON someRecord
Array [Array [String "author",String "Artyom"],Array [String "language",String "English"]]

Perhaps it would be better to convert them to objects instead? I understand that it would make conversions lossy if there are two fields with the same name, but I'm not sure how common that usecase it (in the worst case we could keep current recToVal under a different name, so that if somebody really needed it, they could use it).

agrafix commented 7 years ago

I think you found a bug! I always intended to use objects, and the toEncoding function seems to do the right thing. It looks like the recToValue ( https://github.com/agrafix/superrecord/blob/e19cf6f5d319aa9a15c1068a33ff3a417dab939a/src/SuperRecord.hs#L596-L597 ) functions does not match the recToEncoding function. Would you like to write a test and fix this bug?

neongreen commented 7 years ago

Sure!

neongreen commented 7 years ago

Expect a PR today.

agrafix commented 7 years ago

awesome, thank you!