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

151
Views
Angular 7 HTTP put strips out undefined property

I'm trying to send a HTTP PUT request to an API that accepts a JSON object in its body. Everything works fine, except if I want to set a prop of the body to undefined, that prop will be stripped out entirely from the response object (as if I would call the delete operator for that prop). I checked and I can confirm that the given prop is there, with the value of undefined as long as the object is passed to httpClient.put().

Does anybody know why does this happen? Is this an expected behavior for the http client, or there's a bug somewhere?

about 4 years ago · Juan Pablo Isaza
1 answers
Answer question

0

The behavior you describe it's the expected behavior of HttpClient. Actually, it's the behavior of JSON.stringify() which HttpClient uses behind the scenes.

Unlike JavaScript, JSON doesn't have the concept of undefined. If something is undefined, it's just not defined. It doesn't exist at all. So, when JSON.stringify() gets an object with a property that equals undefined, it omits him.

If you need this property in your request's body, try to change its value to null, empty string, or zero (depending on your server-side).

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!