Fix handling of invalid JSON input

Added a test that trigger the issue and then fixed it.

Ref. #201

Use the exception object itself to generate the error message instead of
its message attribute because that message attribute is no longer valid
in Python 3.