json-override

json-override

The json-override snippet wraps JSON.parse to override values from the same list as override-property-read.

It wraps both JSON.parse and Response.prototype.json, so a payload is covered whether the page parses it itself or reads it straight off a fetch response with await response.json().

Parameters

Name

Description

Mandatory

rawOverridePaths

Space-separated properties to override. Accepts property chains (foo.bar), {} for objects, [] for arrays. Each entry can also be a jsonpath(...) query — see below. The {-} and [-] removal placeholders accepted by json-prune are not supported here, since removing the containing element has no meaning for an override.

Yes

value

The value to override the property with.

Yes

rawNeedlePaths

Space-separated properties — all must be present for override to occur.

No

filter

String or regex to look for in the raw string before JSON.parse. If no match, no further search is done.

No

Possible override values

Value

Definition

undefined


false

The boolean, not the string

true

The boolean, not the string

falseStr

"false" as a string

trueStr

"true" as a string

null


''

Empty string

decimal integer

The number

noopFunc

Function with empty body

trueFunc

Function returning true

falseFunc

Function returning false

emptyArray

Array with no elements

emptyObj

Object with no properties

JSONPath mode

When an entry in rawOverridePaths starts with jsonpath(, the query is evaluated against the parsed object and every property it matches is overridden with value, interpreted through the vocabulary above. Use it when the placeholder syntax cannot express the shape you need — for example filtering on a sibling property's value, or matching at an unknown depth with $...

  • rawOverridePaths is split on spaces, so a query must not contain spaces.

  • Quotes inside a filter expression must be written \', or the parser strips them.

  • Entries are evaluated independently, so plain properties and queries can be mixed in one filter.

  • For the supported query syntax, see JSONPath evaluator. For the escaping rules, see Snippets Overview.

Filter examples

Filter

Result

json-override ghl_label ''

Replaces ghl_label with empty string from every object parsed with JSON.parse.

json-override 'children text' ''

Replaces all children and text properties with empty string.

json-override ghl_label '' text

Replaces ghl_label from every object that has a text property.

json-override data.nested.[].ad ''

Replaces all ad values listed inside an array with empty string.

json-override data.nested.{}.ad ''

Replaces ad values from any nested object properties.

json-override 'jsonpath($..ads.enabled)' false

JSONPath mode. Sets every ads.enabled property at any depth to the boolean false.

json-override 'jsonpath($.items[?(@.type==\'ad\')].visible)' false

Sets visible to false only on the items elements whose type is ad — a condition on the data that the placeholder syntax cannot express.

Debugging

Message

When

Definition

Wrapped JSON.parse for override

After wrapping

The API was wrapped.

Wrapped Response.json for override

After wrapping

Payloads read via await response.json() are covered too.

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

Parsing placeholder

The path leading to the placeholder is accurate.

Found <<rawOverridePath>> replaced it with <<value>>

After override

A property was found and overridden.

Invalid JSONPath query: <<path>>. Error: <<message>>

Right after the snippet fires

The query could not be compiled, so that entry will never match.

JSONPath match found at [<<key>>], replaced with <<value>>

Per matched property

A property matched the query and was overridden. One message per match.

JSONPath evaluation failed for: <<path>>. Error: <<message>>

Evaluating a compiled query threw

That object is left untouched.