Navigation Menu

Skip to content

Instantly share code, notes, and snippets.

@ferdiemmen
Created December 6, 2017 07:44
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save ferdiemmen/54a12e92ac328d40ceee20e8067cab44 to your computer and use it in GitHub Desktop.
Save ferdiemmen/54a12e92ac328d40ceee20e8067cab44 to your computer and use it in GitHub Desktop.
Json stringify ignores keys whose values are undefined
var breakfast = {
"cereal" : "fruit loops",
"pastry" : undefined
};
console.log(breakfast);
// -> { cereal: 'fruit loops', pastry: undefined }
console.log(JSON.stringify(breakfast));
// -> {"cereal":"fruit loops"}
https://stackoverflow.com/questions/31284216/why-does-json-stringify-ignore-keys-whose-values-are-undefined
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment