Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

225
Views
How to convert formData to JSON with entry keys interpreted as array and object keys?

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!

about 4 years ago · Santiago Gelvez
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!