I have a form with inputs named like so:
<input name="locations[0][name]" value="x">
I want to convert it to JSON so it looks like:
{
"locations": [
{
"name": "x"
}
]
}
I've tried (per this StackOverflow post):
var object = {};
formData.forEach((value, key) => object[key] = value);
var json = JSON.stringify(object);
But I end up with the key treated as a string:
{
"locations[0][name]": "x"
}
How can I encode in JSON and use the input names to create an object/array structure? Thanks!