json-override
The json-override
snippet wraps JSON.parse
to override values from the same list as override-property-read
.
Parameters
rawOverridePaths
A list of space-separated properties to remove. It also accepts property chains - e.g. foo.bar.tar
.
Can include placeholders {}
and []
to iterate over nested objects and arrays respectively.
Yes
value
The value to override the property with.
Yes
rawNeedlePaths
A list of space-separated properties. All must be present for pruning to occur. Also accepts property chains.
No
filter
A string to look for in the raw string, before it's passed to JSON.parse
. If no match is found, no further search is done on the resulting object.
If the string begins and ends with a slash (/
), the text in between is treated as a regular expression.
No
Possible override values
undefined
false
true
null
" "
An empty string
decimal integer
noopFunc
A function with an empty body
trueFunc
A function that returns true
emptyArray
An array with no elements
emptyObj
An object with no properties
Filter examples
The following table lists examples that use the json-override
snippet:
json-override ghl_label ''
Replaces the ghl_label
property value (if found) with an empty string from every object parsed with JSON.parse
.
json-override 'children text' ''
Replaces all children
and text
property values (if found) with an empty string from every object parsed with JSON.parse
.
json-override ghl_label '' text
Replaces any ghl_label
property value (if found) with an empty string from every object that has a text
property and is parsed with JSON.parse
.
json-override 'children text' '' 'styles tag'
Replaces all children
and text
property values (if found) from every object that has both the styles and tag properties and is parsed with JSON.parse
.
json-override ghl_label.children '' '' 'test'
Replaces the children
sub-property value of a ghl_label
property (if found) with an empty string only if the raw string contains test
from every object that is parsed with JSON.parse.
json-override data.nested.[].ad ''
Replaces all the ad
values listed inside an array with an empty string.
before
{"data":{ "nested":[ {"ad":"replace me"}, {"ad":"replace me"}, {"ad":"replace me"}, {"not-ad":"don't replace me"}], "hello-world":"don't replace me"} }
after
{"data":{ "nested":[ {"ad":""}, {"ad":""}, {"ad":""}, {"not-ad":"don't replace me"}], "hello-world":"don't replace me"} }
json-override data.nested.{}.ad ''
Replaces ad
values from item1
, item2
, etc. with an empty string.
{}
is a placeholder for any "parent" property of ad.
before
{data: { "nested": { "item1": { "ad": "replace me" }, "item2": { "ad": "replace me" }, "item3": { "ad": "replace me" }, "item4": { "not-ad": "don't replace me" }, "hello-world":"don't replace me"} }
after
{data: { "nested": { "item1": { "ad": "" }, "item2": { "ad": "" }, "item3": { "ad": "" }, "item4": { "not-ad": "don't replace me" }, "hello-world":"don't replace me"} }
Debugging
The following table contains messages you'll find useful during debugging:
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 <<rawOverridePath>>
replaced it with <<value>>
FILTER: json-override '<<param>>'
After a property was overridden.
A property was found and overridden. If rawOverridePaths
has multiple paths, we will see a message for each found path.
The filter that successfully overrode the property (the parameters will be individually wrapped in single quotes).
Last updated