I have a JSON array object called contacts:
var contacts = [];
After some processing the value of contacts look like:
[{ "Country":"country 1", "Phone":"123" },{ "Country":"country 2", "Phone":"456" }]
Now I want to add this to the "Contacts" name inside the formdata. For that I use:
var formdata = new FormData();
formdata.append("Contacts", JSON.stringify(contacts));
When I try alert(JSON.stringify(formdata)); on button click I get:
\"Contacts\":\"[{\\\"Country\\\":\\\"country 1\\\",\\\"Phone\\\":\\\"123\\\"},
{\\\"Country\\\":\\\"country 2\\\",\\\"Phone\\\":\\\"456\\\"}]\"}"
The problem is that in the API, its not detecting the list of contacts. I tried using POSTMAN as:
Contacts[0].Country : country 1
Contacts[0].Phone : 123
Contacts[1].Country : country 2
Contacts[1].Phone : 456
API accepts data in that case. API accepts rest of the formdata fields except this, just sharing this info to rule out issue with api.
API accepts a collection of contacts as well as other fields like Name, Age and then Contacts.
console.log()instead ofalert().