Moved main json workhorse method to closure for easily overriding.

Moved the work of the json() method to a closure, allowing users to override json() if they wish, and return, for example, a Hal object.