refactor withJson method.