Breadcrumbs

JSONPath evaluator

Overview

A lightweight JSONPath engine is supported within the json-prune, json-override, replace-xhr-response, replace-xhr-request, and replace-fetch-request snippets. This allows for precise targeting of properties within JSON objects using standard path notation.

To use JSONPath in a filter, prefix the path argument with jsonpath(. If the prefix is omitted, the snippet falls back to its standard behaviour.

Supported Syntax

Operator

Name

Description

Example

$

Root

Represents the root object of the JSON structure.

$.data

.

Dot Access

Accesses a child property by name.

$.store.book

..

Recursive descent

Searches for a key at any level of the hierarchy.


$..ad_id

*

Wildcard

Matches all child properties or array elements.

$.items[*]

[]

Bracket notation

Used for keys with special characters, indexes, or filter expressions.

$['complex-key']

[?()]

Filter expression

Filters objects based on a property comparison.

[?(@.type=='ad')]

Filter Comparison Operators

Within a [?()] expression, the following comparison operators are supported:

  • Equality / Inequality: ==, !=

  • Numeric / Lexical: <, <=, >, >=

  • String matching: ^= (starts with), $= (ends with), *= (contains)

Quoting a string inside a filter expression

The operator table above shows plain JSONPath. Inside an actual filter, the quotes around a string have to be written \', because the snippet filter parser treats a bare ' as a quote toggle and strips it — [?(@.type=='ad')] would reach the engine as [?(@.type==ad)]. For the same reason, a value containing a space needs surrounding single quotes so it stays one parameter. See Snippets Overview for the full escaping rules.

Examples

Filter

Result

example.com#$#json-prune jsonpath($..ad_tracking)

Removes every instance of ad_tracking found at any depth.

example.com#$#json-override jsonpath($.items[?(@.is_sponsored==true)].label) 'Clean Content'

Overrides the label property to Clean Content only on items where is_sponsored is true. The single quotes keep the value as one parameter.

example.com#$#json-prune jsonpath($.metadata.*)

Removes all properties within the metadata object.

example.com#$#json-prune jsonpath($..trackingId)

Removes every instance of trackingId at any depth.

example.com#$#json-override jsonpath($.ads[?(@.type==\'banner\')].visible) false

Sets visible to false on all banner-type ad objects. The inner quotes are escaped so the parser passes them through.