New Research: Supply Chain Attack on Axios Pulls Malicious Dependency from npm.Details →
Socket
Book a DemoSign in
Socket

jsonpath-blacklist

Package Overview
Dependencies
Maintainers
1
Versions
5
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

jsonpath-blacklist

Simple masking of JSON object with a list of JsonPath

latest
Source
npmnpm
Version
1.0.6
Version published
Maintainers
1
Created
Source

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_>'] }}

Keywords

json

FAQs

Package last updated on 19 Apr 2020

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts