C#C
C#•4y ago
malkav

Making an azure Function to merge two JSON objects

I'm trying to make an Azure Function to merge two JSON objects, but apparently azure Functions don't like the idea of adding a JSON like this:
{ "main_object": "{ \"name\": \"some name\", \"more_properties\": \"values\" }" }

so now I'm trying to figure out how to make sure I can pass two json objects of which I not know their data into the request body.
My parameters on the request body should be
(JSON)main_object
,
(JSON)secondary_object
,
(anything, so JToken??)matching_property
,
(string[])merge_properties


Does this mean I should be using
JToken
?
currently I'm trying this:
[FunctionName("MergeSingleAsync")]
public static async Task<IActionResult> RunAsync(
[HttpTrigger(AuthorizationLevel.Function, "post", Route = null)]
HttpRequest req, ILogger log)
{
  string requestBody = await new StreamReader(req.Body).ReadToEndAsync();
  Inputs data = JsonConvert.DeserializeObject<Inputs>(requestBody);
  // ...
}

class Inputs
{
  [JsonProperty("main_object")] public string MainObject {get;set;} // Should be JToken??
  [JsonProperty("secondary_object")] public string SecondaryObject {get;set;} // Should be JToken??
  [JsonProperty("matching_property")] public JToken MatchingProperty {get;set;}
  [JsonProperty("merge_properties")] public string[] MergeProperties {get;set;}
}

I would love some assistance 😅 I'm stuck at this for 2 days now
Was this page helpful?