I use JSON.stringify(value, replacer) to mask sensitive data in JSON object.
const inputJsonObject =
{
"id": "uniqueId",
"value": "objectData",
"user": {
"password": "qwerty"
}
};
const hideDataMethod = JSON.stringify(inputJsonObject, (key, value) => {
const dataToHide = ['id', 'user.password'];
return dataToHide.indexOf(key) === -1 ? value : 'xxx';
});
console.log(hideDataMethod);
How to get to user.password value? The above solution works for id but doesn't for password.
passwordnotuser.passwordinputJsonObjectis not JSON, it's just an object. JSON is a textual notation for data exchange. (More here.) If you're dealing with JavaScript source code, and not dealing with a string, you're not dealing with JSON. (Similarly,hideDataMethodisn't a method, it's a string.)