Use JSON as exception format

This allows us to provide more structured error information.
Merge pull request #712 from ahocevar/json-exception

Use JSON as exception format