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

72
Views
Convert FormData to json with grouped properties

I have a form, let's say:

<form action="bla">
    <div>
        <input name="form[row1][foo]"
        <input name="form[row1][bar]"
    </div>
    <div>
        <input name="form[row2][foo]"
        <input name="form[row2][bar]"
    </div>
    <div>
        <input name="form[row3][foo]"
        <input name="form[row3][bar]"
    </div>
</form>

I want to convert that FormData to json but when I do that

var formData = new FormData(myForm);
var jsonData = Object.fromEntries(formData.entries());

what I get is an object like:

{
    "form[row1][foo]": "foo1",
    "form[row1][bar]": "bar1",
    "form[row2][foo]": "foo2",
    "form[row2][bar]": "bar2",
    "form[row3][foo]": "foo3",
    "form[row3][bar]": "bar3"
}

but what I want is something like this:

{
    "form": {
        "row1": {
            "foo": "foo1",
            "bar": "bar1"
        },
        "row2": {
            "foo": "foo2",
            "bar": "bar2"
        },
        "row3": {
            "foo": "foo3",
            "bar": "bar3"
        }
    }
}

Is that possible and how?

about 4 years ago · Juan Pablo Isaza
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!