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 |
|---|---|---|
|
|
Space-separated properties to override. Accepts property chains ( |
Yes |
|
|
The value to override the property with. |
Yes |
|
|
Space-separated properties — all must be present for override to occur. |
No |
|
|
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 |
|---|---|
|
|
|
|
|
The boolean, not the string |
|
|
The boolean, not the string |
|
|
|
|
|
|
|
|
|
|
|
Empty string |
|
|
The number |
|
|
Function with empty body |
|
|
Function returning true |
|
|
Function returning false |
|
|
Array with no elements |
|
|
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 $...
-
rawOverridePathsis 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 |
|---|---|
|
|
Replaces |
|
|
Replaces all |
|
|
Replaces |
|
|
Replaces all |
|
|
Replaces |
|
|
JSONPath mode. Sets every |
|
|
Sets |
Debugging
|
Message |
When |
Definition |
|---|---|---|
|
|
After wrapping |
The API was wrapped. |
|
|
After wrapping |
Payloads read via |
|
|
Parsing placeholder |
The path leading to the placeholder is accurate. |
|
|
After override |
A property was found and overridden. |
|
|
Right after the snippet fires |
The query could not be compiled, so that entry will never match. |
|
|
Per matched property |
A property matched the query and was overridden. One message per match. |
|
|
Evaluating a compiled query threw |
That object is left untouched. |