I want to pass json object as a query string parameter (not from body) to ASP.NET Core Web API url from postman. Kindly let me know how to pass? below the sample JSOB object structure :
here, 'names's is string array
"students":[
{
"id":"1",
"names":["john", "james"]
},
{
"id":"2",
"names":["peter", "harry"]
}
]
This is a demo I made , you could refer to
In Postman , remember to set "Content-Type" to "application/json" in the Headers, otherwise you might get a error - 415 Unsupported MediaType.
https://localhost:44388/api/student/?students[0].id=1&students[0].name[0]=john&students[0].name[1]=james&students[1].id=2&students[1].name[0]=peter&students[1].name[1]=harry
The Student Model
public class Student
{
public int Id { get; set; }
public string[] Name { get; set; }
}
In Controller , do not forget add [FromQuery] in the parameter of action.
[Route("api/[controller]")]
[ApiController]
public class StudentController : ControllerBase
{
[HttpPost]
public void PostStudent([FromQuery]List<Student> students)
{
}
}
The screenshot of students parameter

As Gabriel Luci said ,the Json object is best passed in the body of request.
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