Skip to content

Instantly share code, notes, and snippets.

@djD-REK
Created August 16, 2019 22:12
Show Gist options
  • Save djD-REK/bb63f7963aedb3a510d08f960c5c3144 to your computer and use it in GitHub Desktop.
Save djD-REK/bb63f7963aedb3a510d08f960c5c3144 to your computer and use it in GitHub Desktop.
const user = {
id: 101010,
name: "Derek",
email: "[email protected]"
};
function replacer(key, value) {
if (typeof value === "number") {
return undefined;
}
if (key === "email") {
return "Removed for privacy";
}
return value;
}
console.log(JSON.stringify(user));
// result: {"id":101010,"name":"Derek","email":"[email protected]"}
console.log(JSON.stringify(user, replacer));
// result: {"name":"Derek","email":"Removed for privacy"}
console.log(JSON.stringify(user, null, "^_^ "));
// result: {
// ^_^ "id": 101010,
// ^_^ "name": "Derek",
// ^_^ "email": "[email protected]"
// }
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment