My ASP.NET Core endpoint accepts a JSON form as its input and calls a method that expects a dynamic argument. I am attempting to call the method like this:
[HttpPost]
public IActionResult InitializeAction([FromBody] dynamic jsonData)
{
return this.Ok(this.MyMethod(jsonData));
}
When I POST the JSON {"test": "value"} to this method, I would expect identical behavior to doing the following:
[HttpPost]
public IActionResult InitializeAction([FromBody] dynamic jsonData)
{
return this.Ok(this.MyMethod(new {test = "value"}));
}
However, the JSON value retrieved using the [FromBody] parameter does not get converted to a standard .NET dynamic argument, and is instead a JsonDocument or JsonElement or something along those lines.
How do I receive or serialize the JSON from the HTTP Post as a .NET dynamic object?




dynamic data = JsonConvert.DeserializeObject<dynamic>(jsonData.ToString())to get what I am looking for. Is there a way to get my intended result without first converting thejsonDataargument to a string, or is this the right answer?