1.0.1 • Published 4 years ago

json-string-redactor v1.0.1

Weekly downloads
2
License
ISC
Repository
-
Last release
4 years ago

json-string-redactor

Redacts JSON string values for specified keys

travis

npm i json-string-redactor

Example

const jsonRedactor = require('json-string-redactor');

const input = JSON.stringify({
  name: 'Test0',
  prop0: 'I should not be redacted',
  child: {
    name: 'Test1',
    prop1: 'I should not be redacted either',
    child: {
      name: 'Test2',
      child: {
        name: 'Test3',
        secret: 'This is a secret',
      },
    },
  },
});

const redacted = jsonRedactor(['name', 'secret'], input);
/*
redacted is now: 
{
  "name": "*****",
  "prop0": "I should not be redacted",
  "child": {
    "name": "*****",
    "prop1": "I should not be redacted either",
    "child": {
      "name": "*****",
      "child": {
        "name": "*****",
        "secret": "****************"
      }
    }
  }
}
*/

Note: You get 1 * per character redacted :)