Parsing JSON with Purescript
I just wrote a lambda that responds to S3 events. I wrote it in Node. The JSON strcture of an S3 event is fairly complex. It is even worse when the event comes over SNS.
Handling the events in Node was error prone and testing took a while. Also, SNS will sometimes send test events that are imcomplete. This results in many failures due to missing keys. Undefined errors are not your friend.
I wanted to parse the JSON and handle error conditions more gracefully.
In this example, I'm only interested in the bucket and key of the S3 object. The parser wades through the other data and builds an S3 data type. If the bucket and key aren't present, or the JSON is malformed, then an error is returned as a Left. If the errors aren't handled then the program won't compile.