Encode the returned result to JSON