Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Field with undefined value set is being removed from data object #854

Closed
jdpagley opened this issue Apr 23, 2017 · 3 comments
Closed

Field with undefined value set is being removed from data object #854

jdpagley opened this issue Apr 23, 2017 · 3 comments

Comments

@jdpagley
Copy link

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.

@sunnykgupta
Copy link

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

@jdpagley
Copy link
Author

@sunnykgupta that works! Thanks for the workaround :)

@rubennorte
Copy link
Member

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

@axios axios locked and limited conversation to collaborators May 22, 2020
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants