Adding a to_json utility method.