It can be a pain to return json-responses from a Function App, when you also want the proper Content-Type HTTP header to be returned, which it of course should.
If you do it the straight-forward way (works the same with OkObjectResult) –
return new BadRequestObjectResult(jsonResponse);
if response contains a json string, it will be returned ok, but the Content-Type will be “text/plain”
BadRequestObjectResult resp = new BadRequestObjectResult(jsonResponse);
resp.ContentTypes.Add(MediaTypeHeaderValue.Parse("application/json"));
resp.Value = jsonResponse;
return resp;
if response contains a json string, the special characters (like “) will be escaped, and it will no longer return valid json, but the Content-Type is ok (application/json)
If the content-type is not set in above example, the special characters are not escaped
Continue reading “Returning Json response from Azure Function v3+”