json-prune

The json-prune snippet traps calls to JSON.parse and, if the result of the parsing is an Object, it will remove the specified properties from the result before returning to the caller.

Use json-prune when you want to remove properties from an object parsed with JSON.parse.

Parameters

Name
Description
Mandatory

rawPrunePaths

A list of space-separated properties to remove.

Yes

rawNeedlePaths

A list of space-separated properties which must be all present for the pruning to occur. Can include placeholders {} and [] to iterate over nested objects and arrays respectively.

No

rawNeedleStack

A list of space-separated strings or regex which must be present in the JSON.prune call stack for the pruning to occur.

No

Filter examples

The following table lists examples that use the json-override snippet:

Filter
Result

json-prune ads

Removes any ads property (if found) from every object parsed with JSON.parse.

json-prune 'ads videoAds'

Removes all ads and videoAds properties (if found) from every object parsed with JSON.parse.

json-prune ads userId

Removes any ads property (if found) from every object parsed with JSON.parse with a userId property.

json-prune 'ads videoAds' userId

Removes all ads and videoAds properties (if found) from every object parsed with JSON.parse with a userId property.

json-prune 'ads videoAds' 'userId title'

Removes all ads and videoAds properties (if found) from every object parsed with JSON.parse that has both userId and title properties.

json-prune data.nested.[].ad

Removes all the ad properties listed inside an array: before {"data":{ "nested":[ {"ad":"delete me"}, {"ad":"delete me"}, {"ad":"delete me"}, {"not-ad":"don't delete me"}], "hello-world":"don't delete me"} } after {"data":{"nested":[{}, {}, {}, {"not-ad":"don't delete me"}],"hello-world":"don't delete me"}}

json-prune data.nested.{}.ad

Removes all the ad properties listed inside an object, without mentioning the key of each object: before {"data": {"nested": {"item1":{}, "item2":{}, "item3":{}, "item4":{"not-ad":"don't delete me"} }, "hello-world":"don't delete me"} } after {"data":{"nested":{"item1":{},"item2":{},"item3":{},"item4":{"not-ad":"don't delete me"}},"hello-world":"don't delete me"}}

json-prune ads '' functionName

Removes any ads if in the call stack trace functionName is found.

json-prune ads '' /innerFunctionName(.|\\n)*outerFunctionName/

Removes any ads if in the call stack trace innerFunctionName and outerFunctionName are found. The regex pattern (.|\\n) is used to match these function names, ignoring any content or new lines in between. However, note that regex flags for single-line (/s) or multi-line (/m) matching will not work. When crafting the regex for the call stack trace, remember that functions are listed from the innermost (most recent) to the outermost (earlier) calls. So, the innermost functions appear first in the trace, while previous function calls appear later.

Debugging

The following table contains messages you'll find useful during debugging:

Message
When the message occurs
Definition

Wrapped JSON.parse

After JSON.parse has been wrapped

The snippet was injected and the API was wrapped.

Iterating over array at [] or Iterating over object at {}

The snippet is parsing the placeholder.

The path leading up to the placeholder is accurate. If a success log does not follow this, it indicates that the filter needs further refinement beyond the placeholder.

Found needle in stack trace: <<rawNeedleStack>>

After comparing the passed <<rawNeedleStack>> param against the JSON.parse stack trace.

The needle has been successfully found.

Needle <<rawNeedleStack>> not found in stack trace: <<stack trace>>

After comparing the passed <<rawNeedleStack>> param against the JSON.parse stack trace.

The needle remains unfound. To assist in fine-tuning the <<rawNeedleStack>> parameter, the stack trace will be logged for further analysis.

Found <<rawPrunePaths>> and deleted. FILTER: json-prune '<<param>>'

After a property was deleted.

A property was found and deleted. If rawPrunePaths has multiple paths, we sill see a message for each found path, along with the filter that successfully deleted the property (the parameters will be individually wrapped in single quotes).

Last updated