I am playing with Azure Functions. However, I feel like I\'m stumped on something pretty simple. I\'m trying to figure out how to return some basic JSON. I\'m not sure how to cr
Here's a full example of an Azure function returning a properly formatted JSON object instead of XML:
#r "Newtonsoft.Json"
using System.Net;
using Newtonsoft.Json;
using System.Text;
public static async Task<HttpResponseMessage> Run(HttpRequestMessage req, TraceWriter log)
{
var myObj = new {name = "thomas", location = "Denver"};
var jsonToReturn = JsonConvert.SerializeObject(myObj);
return new HttpResponseMessage(HttpStatusCode.OK) {
Content = new StringContent(jsonToReturn, Encoding.UTF8, "application/json")
};
}
Navigate to the endpoint in a browser and you will see:
{
"name": "thomas",
"location": "Denver"
}