refactor ctx.toJSON() to recurse. Closes #108