Fixes #235 - Return a proper error message when JSON payload is malformed.

@cvan Is this a correct solution?