• Empleos
  • Sobre nosotros
  • profesionales
    • Inicio
    • Empleos
    • Cursos y retos
    • Preguntas
    • Profesores
  • empresas
    • Inicio
    • Publicar vacante
    • Nuestro proceso
    • Precios
    • Pruebas Online
    • Nómina
    • Blog
    • Comercial
    • Calculadora de salario

0

106
Vistas
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?

almost 3 years ago · Juan Pablo Isaza
1 Respuestas
Responde la pregunta

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).

almost 3 years ago · Juan Pablo Isaza Denunciar
Responde la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Nuestro proceso Comercial
Legal
Términos y condiciones Política de privacidad
© 2025 PeakU Inc. All Rights Reserved.

Andres GPT

Recomiéndame algunas ofertas
Necesito ayuda