4 ms·
I really wish that Aeson's lookups and fromJSON returned Eithers, and not Maybes. If you try to parse a deeply nested structure represented in JSON, and just ge
by thinkpad20 12y ago
I really wish that Aeson's lookups and fromJSON returned Eithers, and not Maybes. If you try to parse a deeply nested structure represented in JSON, and just get a Nothing back, it really doesn't help you very much. Having an Either is much more helpful.
(If anyone is aware of a canonical library for this, let me know. I wrote my own JSON library which has this functionality but it's not particularly robust or performant).
- taylorfausak 12y agoYou can use eitherDecode to get that behavior. http://hackage.haskell.org/package/aeson-0.8.0.0/docs/Data-Aeson.html#v:eitherDecode http://hackage.haskell.org/package/aeson-0.8.0.0/docs/Data-A...
- koomi 12y agoAeson's «fromJSON» returns a «Result» which is basically «Either String». Most other functions operate on «Parser», which also includes an error message if things go wrong. The only functions returning «Maybe» are «decode» and friends, and those have «Either String» variants. You can use «modifyFailure» and «typeMismatch» (and the «with» wrappers) to get more descriptive messages, without a bit of help they are quite useless.