"I have create a Azure Function in this function I call an API that returns JSON. I want to parse this JSON to an object so I can use it in the function. I cannot not use Newton.JSON as the function seems not to know this. How can I parse the JSON?"
Folder structure. The code for all the functions in a specific function app is located in a root project folder that contains a host configuration file. The host. json file contains runtime-specific configurations and is in the root folder of the function app.
parse() The JSON. parse() method parses a JSON string, constructing the JavaScript value or object described by the string. An optional reviver function can be provided to perform a transformation on the resulting object before it is returned.
Azure SQL Database and Azure SQL Managed Instance let you parse and query data represented in JavaScript Object Notation (JSON) format, and export your relational data as JSON text. The following JSON scenarios are available: Formatting relational data in JSON format using FOR JSON clause.
Using 'parse JSON' action The value of content will be the 'body' value from 'Send an HTTP request to SharePoint. Now configure the schema correctly. In most cases this value is configured incorrectly which would result in null values. Click on 'Generate from sample' and then you will be getting the below pop-up.
Here is a complete Azure Function source code for serializing/deserializing objects using JsonNet:
#r "Newtonsoft.Json"
using System.Net;
using Newtonsoft.Json;
public static async Task<HttpResponseMessage> Run(HttpRequestMessage req, TraceWriter log)
{
dynamic body = await req.Content.ReadAsStringAsync();
var e = JsonConvert.DeserializeObject<EventData>(body as string);
return req.CreateResponse(HttpStatusCode.OK, JsonConvert.SerializeObject(e));
}
public class EventData
{
public string Category { get; set; }
public string Action { get; set; }
public string Label { get; set; }
}
Sample input (request body):
{
"Category": "Azure Functions",
"Action": "Run",
"Label": "Test"
}
Sample output:
"{\"Category\":\"Azure Functions\",\"Action\":\"Run\",\"Label\":\"Test\"}"
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With