I am writing a Node.js server which needs to accept a stringified JSON object in one of its services. I also want to whitelist certain fields in the JSON object. Both of these tasks should be accomplishable using JSON.parse() with the reviver parameter.
For some reason, trying to whitelist fields based on the key returns undefined
for me. Curiously, I am able to successfully blacklist fields, as seen in this jsfiddle.
Can anyone explain this behavior and fix the first console.log
statement to return {a="A"}
?