Miss any of our Open RFC calls?Watch the recordings here! »

jsonpath-blacklist

1.0.6 • Public • Published

Build Status Coverage Status Run on Repl.it

JsonPath Blacklist

Simple function for masking JSON with a list of JsonPaths

Usage

var blacklist  = require('jsonpath-blacklist');
 
var inputJSON = { a: 'keep', b: { c: ['keep', 'remove', 'remove']}};
 
var outputJSON = blacklist(['b.c[1]', 'b.c[2]'], inputJSON);
console.log(outputJSON);
// { a: 'keep', b: { c: ['keep'] }}
 
// Note that inputJSON is also changed.
console.log(inputJSON);
// { a: 'keep', b: { c: ['keep'] }}
 
// Object
outputJSON = blacklist(['b.c'], inputJSON);
console.log(outputJSON);
// { a: 'keep', b: {}}
 
// Attribute
outputJSON = blacklist(['a'], inputJSON);
console.log(outputJSON);
// { b: {}}

To avoid modification to the input, we can use an options argument:

var blacklist  = require('jsonpath-blacklist');
 
var options = { deepCopy: true }
var inputJSON = { a: 'keep', b: { c: ['keep', 'remove', 'remove']}};
 
var outputJSON = blacklist(['b.c[1]', 'b.c[2]'], inputJSON);
console.log(outputJSON);
// { a: 'keep', b: { c: ['keep'] }}
 
console.log(inputJSON);
// { a: 'keep', b: { c: ['keep', 'remove', 'remove']}}

You can also replace the masked jsonpath is a string:

var blacklist  = require('jsonpath-blacklist');
 
var options = { replacement: '<_masked_>' }
var inputJSON = { a: 'keep', b: { c: ['keep', 'remove', 'remove']}};
 
var outputJSON = blacklist(['b.c[1]', 'b.c[2]'], inputJSON);
console.log(outputJSON);
// { a: 'keep', b: { c: ['keep', '<_masked_>', '<_masked_>'] }}

Install

npm i jsonpath-blacklist

DownloadsWeekly Downloads

0

Version

1.0.6

License

ISC

Unpacked Size

69.7 kB

Total Files

12

Last publish

Collaborators

  • avatar