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

177
Views
Need to covert form value to object after appending to formdata

Trying to submit a form using formgroup, Initially the for value was an object but after appending to formdata the value becomes string so that i cannot parse the data in query.

users form value after submit:-

[
   {
    "id": "",
    "employee": "6166d234379ec5e4c9b3fe3",
    "position": "Manager",
    "users": [
        "715ea5df332403e4215324234",
        "815ea33534534333e42153432"
    ],
  }
]

 Object.keys(this.Form.controls).forEach(key => {
      if(key == 'users'){
     console.log(typeof(this.Form.get(key).value)) //type is object
     formData.append(key,this.Form.get(key).value);
    }
  });

 formData.forEach((value,key) => {
       console.log(key+" "+typeof(value)) // type of value  becomes  string
 });

 //trying covert it to object
 formData.forEach((value,key) => {
  if(key == 'users'){
       formData.set(key,JSON.parse(JSON.stringify(value)));
       //formData.set(key,JSON.parse(value)); //return error SyntaxError: Unexpected token o 
    in JSON at position
       console.log(key+" "+typeof(value)) // still string
   }
});

 need to submit the formdata with users as object
about 4 years ago · Juan Pablo Isaza
1 answers
Answer question

0

FormData can only be simple key/value pairs of strings. If you must use a FormData object, you can experiment with appending your values as json-encoded strings:

formData.append(key, JSON.stringify(this.Form.get(key).value));

This will allow you to parse the values later:

 formData.forEach((value, key) => {
       console.log(key, JSON.parse(value));
 });
about 4 years ago · Juan Pablo Isaza Report
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!