Reputation: 21
I'm creating an Api using .Net Core 3.1 in which I need one property input as JSON in the controller, something like:
{
"name": "test",
"JSONData": { "roles": ["data1", "data2"] }
}
so that I can define the request something like:
public class MyRequest
{
public string Name { get; set;}
public JSON JSONData { get; set; }
}
I'm thinking of having it as a string and using Serialize/Deserialize it if we cannot have it as a "JSON" data type. Is there a way to have a property as JSON type from both request and response?
Upvotes: 0
Views: 1219
Reputation: 21
I've just tried with JsonElement and could see it works; only one issue that the property is not showing up from the swagger UI. So the request is like:
public class MyRequest
{
public string Name { get; set;}
public JsonElement JSONData { get; set; }
}
Upvotes: 2