JSONPath for data redaction in Rewst
In the Security setting menu of any action, you have the option to use the Redacted fields to customize how Rewst handles sensitive information.

Jinja versus JSONPath with complex nested data
Imagine that you have a large JSON payload returned from an API containing organizations, users, and each user’s list of devices and activity logs. Your goal would be to get all the login timestamps for every device owned by the admin user.
Example JSON
Example Jinia list comprehension
This solution works for your goal, but it's dense, and leaves chains of loops and filters that can be hard to read or debug given how nested the code becomes.
Instead, you could use JSONPath for a much simpler situation that requires just one line to navigate straight down the structure. You can combine multiple queries to redact several fields at once. Test redaction by reviewing task logs. Sensitive fields will appear as ********.
Example JSONPath
$- CTX.organizations[*]- all organizations in the arrayusers[?(@.role=="admin")]- only admin usersdevices[*].activity[?(@.event=="login")].timestamp- login timestamps from all devicesextended=True- allows us to use the filtering on the event and loging
When to use JSONPath versus comprehension
Generally:
Use JSONPath when you're extracting or redacting specific data fields. JSON answers the question 'Where is this data?'
Use comprehension when you're filtering, flattening, or transforming data for workflow logic. Comprehension answers the question 'What do I want to do with this data?'
Simple field extraction: names, IDs, tags
✅
✅
Fast redaction or security masking
✅
❌
Conditional filters or comparisons
✅ - extended=True
✅ - if condition
Flattening nested arrays
⚠️ - multi-wildcards required
✅ - easier and cleaner
Data transformation or mapping
❌
✅
Building dictionaries or composite structures
❌
❌
Large static datasets - speed
✅
⚠️ - slightly slower
Workflow logic or variable formatting
⚠️ - limited
✅ - recommended
Redaction contexts
✅ - required
❌ - unsupported
Example combo use of JSONPath and comprehension
There are instances where it makes sense to use both methods together: extract with JSONPath to quickly isolate the structure, then filter or transform with comprehension to handle things like logic, mapping, and formatting inline.
The result would be:
Further examples
Examples for security redaction
Mask credentials
$..password, $..Authorization, $..tokens[*].value
Mask sensitive IDs
$..id
Mask partial sets
$.result.services[0].users[0:2].username or [-2:].username
Simple mode - extended=False, default
Simple mode supports:
Dot navigation (
.field)Index access (
[0])Wildcards (
[*])Slicing (
[start:end])Recursive search (
$..)Always returns a list
Example
Result
Extended mode - extended=True
Extended mode adds support for filters and comparisons — allowing you to query data by field values directly inside Jinja.
Conditional filters:
?(@.field == value)Comparisons:
==,<,>,>=,<=Existence checks:
?(@.field)
Example
Result
JSONPath summary table
.field navigation
✅
✅
Basic key navigation
[index] access
✅
✅
Select specific array index
Wildcard [*]
✅
✅
Iterate over all list items
Slice [start:end]
✅
✅
Works like Python slice
Negative / step slices
✅
✅
Negative and stepped slices supported
Recursive $..
✅
✅
Deep search anywhere in structure
Filters ?()
❌
✅
Simple comparisons and existence checks only
Comparisons (==, <, >, >=, <=)
❌
✅
Standard numeric or string compare
Logical ops (&&, II, !)
❌
❌
❌ Unsupported
Regex match (=~)
❌
❌
❌ Unsupported
Membership tests (in, not in)
❌
❌
❌ Unsupported
Multi-index [0,2]
❌
❌
❌ Unsupported
Returns list always
✅
✅
Always a list, even single item
Existence filter ?(@.field)
❌
✅
Supported in extended mode
Usage tips
Simple mode (
extended=False) is faster and safe for all Rewst workflow operations, including redaction.Extended mode (
extended=True) adds filters, conditions, and regex — great for debugging or complex data exploration.Always start with
$(the root).Use wildcards
[*]and slices[start:end]to extract lists.Wrap uncertain paths in
{% try %}...{% catch %}to avoid render errors.
Example API response CTX.Extracted_Data
Visual path examples with Jinja and results
Your CTX.Extracted_Data looks like this:
Rewst JSONPath visual path examples
All examples reference CTX.Extracted_Data — the full JSON at the end of this document.
All usernames
Path
Data context
Jinja
Result
First user’s username - Alice
Path
Data context
Jinja
Result
Second user - Bob
Path
Data context
Jinja
Result
First two users - slice example
Path
Data context
Jinja
Result
All roles - flattened
Path
Data context
Jinja
Result
Service names
Path
Data context
Jinja
Result
Endpoint URLs
Path
Data context
Jinja
Result
Tokens expiring soon - extended=True
Path
Data context
Jinja
Result
Note: no tokens expire within 3000 seconds.
Authorization header exists - extended=True
Path
Data context
Jinja
Result
Document IDs - data-service
Path
Data context
Jinja
Result
All tags - flattened
Path
Data context
Jinja
Result
On-call team member names
Path
Data context
Jinja
Result
For just DevOps:
Result
On-call members only - extended=True
Path
Data context
Jinja
Result
Extract all timestamps anywhere in the structure using $[*]..timestamp style
JSONPath
This searches recursively through the entire object and returns every value found under any key named timestamp.
Example result
Extract timestamps only for login activities using $[*]..activity[?(@.event=="login")].timestamp pattern
JSONPath
This looks everywhere in the JSON for an array named activities, then filters to items where:
and returns only the matching timestamp values.
Example result
Assume the data includes a login event with a timestamp.
JSONPath recap in Rewst
Root ($)
Always starts at top level
$.result
Dot navigation
Access keys
$.result.meta.version
Wildcards [*]
Expand arrays
$.result.services[*].users[*].username
Indexes [0]
Specific item
$.result.services[0].users[2].username
Nested access
Chain deeper
$.result.meta.contact.team[1].members[0].name
Filters
Conditional search (extended mode)
$.users[?(@.role == 'admin')]
Always returns list
Even for single matches
["alice"]
Formatting conventions
Long arrays
['a', 'b', 'c', …]
Deep nested objects
<<TRUNCATED>>
Long strings/tokens
'Bearer sk_test_abc123…xyz'
Rewst Jinja comprehension equivalents for JSONPath
Assume your context variable is:
These examples show how to achieve the same result with JSONPath or Rewst’s enhanced Jinja list comprehensions, using clear, readable variable names to help you understand what each level of the JSON represents.
All usernames
JSONPath
Comprehension
Result
First user’s username - Alice
JSONPath
Comprehension
Result
Second user - Bob object
JSONPath
Comprehension
Result
First two users - Slice example
JSONPath
Comprehension
Result
All roles - flattened
JSONPath
Comprehension
Result
Service names
JSONPath
Comprehension
Result
Endpoint URLs
JSONPath
Comprehension
Result
Tokens expiring soon - less than 3000
JSONPath (extended)
Comprehension
Result
Document IDs - data-service
JSONPath
Comprehension
Result
All tags - flattened
JSONPath
Comprehension
Result
On-call team member names
JSONPath
Comprehension
Result
On-call only - filter
JSONPath (extended)
Comprehension
Result
On-call contact methods - flattened
JSONPath
Not easily supported - requires filters and flattening
Comprehension
Result
Last updated
Was this helpful?
