Add a method to return the payload as JSON, and add supporting tests.