Axios: Field with undefined value set is being removed from data object

Created on 23 Apr 2017  ·  3Comments  ·  Source: axios/axios

axios version 0.16.1
Environment: Mac OS Sierra, Chrome v57

I'm currently using axios.post and when I nest an object inside of the data object it appears to remove the fields inside of the nested object that have a value of undefined set.

For instance:

  update(locationId, vehicleSaleId, payload) {

    //Payload example: {billedFront: undefined}

    return axios.post('/api/vehicleSale.update', { 
        params: {locationId, vehicleSaleId}, 
        payload: payload
      })
      .then((res) => res.data);
  },


Chrome Dev Tools > Network:

{"params":{"locationId":"58e991ddb051fc0f8424552a","vehicleSaleId":"58fa4d2562fd801765652fc3"},"payload":{}}

As you can see payload is just an empty object. It should have a billedFront field that is set to undefined.

Most helpful comment

This isn't a bug the the normal behaviour. JSON.stringify removes undefined properties from the resulting object.

All 3 comments

Try setting it to null as a workaround till this is fixed?

@sunnykgupta that works! Thanks for the workaround :)

This isn't a bug the the normal behaviour. JSON.stringify removes undefined properties from the resulting object.

Was this page helpful?
0 / 5 - 0 ratings

Related issues

altruisticsoftware picture altruisticsoftware  ·  3Comments

ghprod picture ghprod  ·  3Comments

reggi picture reggi  ·  3Comments

emaincourt picture emaincourt  ·  3Comments

helmus picture helmus  ·  3Comments