https://github.com/billykong/jsonpath-blacklist
Simple function for masking JSON with a list of JsonPaths
https://github.com/billykong/jsonpath-blacklist
blacklist json jsonpath mask
Last synced: 2 months ago
JSON representation
Simple function for masking JSON with a list of JsonPaths
- Host: GitHub
- URL: https://github.com/billykong/jsonpath-blacklist
- Owner: billykong
- License: mit
- Created: 2018-06-19T07:07:46.000Z (about 8 years ago)
- Default Branch: master
- Last Pushed: 2022-12-30T20:15:39.000Z (over 3 years ago)
- Last Synced: 2025-10-11T08:55:12.862Z (9 months ago)
- Topics: blacklist, json, jsonpath, mask
- Language: JavaScript
- Homepage:
- Size: 195 KB
- Stars: 0
- Watchers: 1
- Forks: 0
- Open Issues: 8
-
Metadata Files:
- Readme: readme.md
- License: LICENSE
Awesome Lists containing this project
README
[](https://travis-ci.org/billykong/jsonpath-blacklist)
[](https://coveralls.io/github/billykong/jsonpath-blacklist?branch=master)
[](https://img.shields.io/npm/v/jsonpath-blacklist)
[](https://repl.it/github/billykong/jsonpath-blacklist)
# JsonPath Blacklist
Simple function for masking JSON with a list of JsonPaths
## Usage
```JavaScript
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:
```JavaScript
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:
```JavaScript
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_>'] }}
```