11# JMESPath Queries
22
3- Filter and transform output using JMESPath expressions with the ` -q ` or ` --query ` flag.
3+ Filter and transform output using JMESPath expressions with the ` -q ` or ` --query ` flag. redisctl includes 300+ extended functions beyond standard JMESPath.
44
55## Basic Usage
66
@@ -12,7 +12,7 @@ redisctl enterprise cluster get -q 'name'
1212redisctl cloud database get 123:456 -q ' security.ssl_client_authentication'
1313
1414# Get multiple fields
15- redisctl enterprise database get 1: -q ' {name: name, memory: memory_size, port: port}'
15+ redisctl enterprise database get 1 -q ' {name: name, memory: memory_size, port: port}'
1616```
1717
1818## Array Operations
@@ -54,6 +54,20 @@ redisctl cloud subscription list -q "reverse(sort_by(@, &id))"
5454redisctl enterprise database list -q ' [:5]'
5555```
5656
57+ ## Pipelines
58+
59+ Chain operations together with ` | ` for complex transformations:
60+
61+ ``` bash
62+ # Filter -> Sort -> Take top 3 -> Reshape
63+ redisctl enterprise database list -q '
64+ [?status==`active`]
65+ | sort_by(@, &memory_size)
66+ | reverse(@)
67+ | [:3]
68+ | [*].{name: name, memory_gb: to_string(memory_size / `1073741824`)}'
69+ ```
70+
5771## Common Patterns
5872
5973### Extract Single Value
@@ -88,30 +102,82 @@ redisctl cloud subscription list -q 'length(@) == `0`'
88102
89103## Extended Functions
90104
91- redisctl includes 150 + extended JMESPath functions beyond the standard built-ins.
105+ redisctl includes 300 + extended JMESPath functions. Here are the most useful categories:
92106
93107### String Functions
94108
95109``` bash
96- # Uppercase/lowercase
97- redisctl enterprise database list -q ' [].{name: name, status: upper(status )}'
110+ # Case conversion
111+ redisctl enterprise database list -q ' [].{name: upper(name )}'
98112
99113# String manipulation
100114redisctl enterprise cluster get -q ' split(name, `-`)'
101115redisctl enterprise database list -q ' [].{name: trim(name)}'
116+
117+ # Case transformations
118+ redisctl api cloud get /subscriptions -q ' [].{id: id, name: snake_case(name)}'
102119```
103120
104- ### Type Functions
121+ ### Formatting Functions
105122
106123``` bash
107- # Type checking
108- redisctl enterprise database get 1 -q ' {name: name, type: type_of(memory_size)}'
124+ # Format bytes (human readable)
125+ redisctl enterprise database list -q ' [].{name: name, memory: format_bytes(memory_size)}'
126+ # Output: [{"name": "cache", "memory": "1.00 GB"}]
109127
110- # Default values for missing fields
111- redisctl cloud database get 123:456 -q ' {name: name, region: default(region, `"unknown"`)}'
128+ # Format duration
129+ redisctl enterprise database list -q ' [].{name: name, uptime: format_duration(uptime_seconds)}'
130+ # Output: [{"name": "cache", "uptime": "2d 5h 30m"}]
112131
113- # Check if empty
114- redisctl enterprise database get 1 -q ' {name: name, has_endpoints: not(is_empty(endpoints))}'
132+ # Parse bytes
133+ redisctl api cloud get /subscriptions -q ' [].{name: name, bytes: parse_bytes(memory_limit)}'
134+ ```
135+
136+ ### Date/Time Functions
137+
138+ ``` bash
139+ # Human-readable relative time
140+ redisctl cloud task list -q ' [].{id: id, created: time_ago(created_time)}'
141+ # Output: [{"id": "task-123", "created": "2 hours ago"}]
142+
143+ # Format timestamps
144+ redisctl cloud subscription list -q ' [].{name: name, created: format_date(createdAt, `"%Y-%m-%d"`)}'
145+
146+ # Current timestamp
147+ redisctl enterprise cluster get -q ' {name: name, checked_at: now()}'
148+
149+ # Check if weekend/weekday
150+ redisctl cloud task list -q ' [?is_weekday(created_timestamp)]'
151+
152+ # Time calculations
153+ redisctl enterprise database list -q ' [].{name: name, age_days: date_diff(now(), created_at, `"days"`)}'
154+ ```
155+
156+ ### Duration Functions
157+
158+ ``` bash
159+ # Convert seconds to human format
160+ redisctl enterprise database list -q ' [].{name: name, uptime: format_duration(uptime_seconds)}'
161+
162+ # Parse duration strings
163+ redisctl api enterprise get /v1/cluster -q ' {timeout: parse_duration(`"1h30m"`)}'
164+ # Output: {"timeout": 5400}
165+ ```
166+
167+ ### Network Functions
168+
169+ ``` bash
170+ # Check if IP is private
171+ redisctl enterprise node list -q ' [?is_private_ip(addr)].addr'
172+
173+ # Check CIDR containment
174+ redisctl enterprise node list -q ' [?cidr_contains(`"10.0.0.0/8"`, addr)]'
175+
176+ # Get network info
177+ redisctl api enterprise get /v1/cluster -q ' {
178+ network: cidr_network(deployment_cidr),
179+ broadcast: cidr_broadcast(deployment_cidr)
180+ }'
115181```
116182
117183### Math Functions
@@ -122,6 +188,39 @@ redisctl enterprise database list -q '[].{name: name, memory_gb: round(memory_si
122188
123189# Min/max
124190redisctl enterprise database list -q ' max_by(@, &memory_size).name'
191+
192+ # Statistics
193+ redisctl enterprise database list -q ' {
194+ total: sum([].memory_size),
195+ avg: avg([].memory_size),
196+ count: length(@)
197+ }'
198+ ```
199+
200+ ### Semver Functions
201+
202+ ``` bash
203+ # Compare versions
204+ redisctl enterprise cluster get -q ' {
205+ version: version,
206+ needs_upgrade: semver_compare(version, `"7.4.0"`) < `0`
207+ }'
208+
209+ # Check version constraints
210+ redisctl enterprise node list -q ' [?semver_satisfies(redis_version, `">=7.0.0"`)]'
211+ ```
212+
213+ ### Type Functions
214+
215+ ``` bash
216+ # Type checking
217+ redisctl enterprise database get 1 -q ' {name: name, type: type_of(memory_size)}'
218+
219+ # Default values for missing fields
220+ redisctl cloud database get 123:456 -q ' {name: name, region: default(region, `"unknown"`)}'
221+
222+ # Check if empty
223+ redisctl enterprise database get 1 -q ' {name: name, has_endpoints: not(is_empty(endpoints))}'
125224```
126225
127226### Utility Functions
@@ -137,45 +236,98 @@ redisctl cloud database get 123:456 -q '{region: coalesce(region, cloud_region,
137236redisctl enterprise database list -q ' unique([].status)'
138237```
139238
140- ### Date/Time Functions
239+ ### Validation Functions
141240
142241``` bash
143- # Current timestamp
144- redisctl enterprise cluster get -q ' {name: name, checked_at: now()}'
242+ # Validate formats
243+ redisctl enterprise database list -q ' [].{
244+ name: name,
245+ valid_endpoint: is_ipv4(endpoints[0].addr),
246+ valid_uuid: is_uuid(database_id)
247+ }'
145248
146- # Format dates
147- redisctl cloud subscription list -q ' [].{name: name, created: format_date(createdAt, `"%Y-%m-%d"`)} '
249+ # Email validation
250+ redisctl api cloud get /users -q ' [?is_email(email)].email '
148251```
149252
150- ### Validation Functions
253+ ### Encoding Functions
151254
152255``` bash
153- # Validate IPs
154- redisctl enterprise database list -q ' [].{name: name, valid_endpoint: is_ipv4(endpoints[0].addr)}'
256+ # Base64 encode/decode
257+ redisctl enterprise cluster get -q ' {encoded: base64_encode(name)}'
258+ redisctl api enterprise get /v1/cluster -q ' {decoded: base64_decode(encoded_field)}'
259+
260+ # URL encode/decode
261+ redisctl api cloud get /subscriptions -q ' [].{safe_name: url_encode(name)}'
155262```
156263
157- ### Encoding Functions
264+ ### Hash Functions
158265
159266``` bash
160- # Base64 decode
161- redisctl enterprise cluster get -q ' {decoded: base64_decode(encoded_field)}'
267+ # Generate hashes
268+ redisctl enterprise database list -q ' [].{name: name, hash: sha256(name)}'
269+ redisctl api cloud get /subscriptions -q ' [].{id: id, checksum: md5(to_string(@))}'
162270```
163271
164- For a complete list of extended functions, see the
165- [ jmespath-extensions documentation] ( https://github.com/joshrotenberg/jmespath-extensions ) .
272+ ### JSON Patch Functions
273+
274+ ``` bash
275+ # Compare two configs
276+ redisctl enterprise database get 1 -q ' json_diff(current_config, desired_config)'
277+
278+ # Apply patches
279+ redisctl api enterprise get /v1/bdbs/1 -q ' json_patch(@, `[{"op": "add", "path": "/tags", "value": ["prod"]}]`)'
280+ ```
166281
167- ## JMESPath Reference
282+ ### Fuzzy Matching
283+
284+ ``` bash
285+ # Levenshtein distance
286+ redisctl enterprise database list -q ' [?levenshtein(name, `"cache"`) < `3`]'
287+
288+ # Phonetic matching
289+ redisctl api cloud get /users -q ' [?sounds_like(name, `"Smith"`)]'
290+ ```
168291
169- - Strings: ` 'value' ` (single quotes)
170- - Numbers: `` `123` `` (backticks)
171- - Booleans: `` `true` `` , `` `false` ``
172- - Current element: ` @ `
173- - Child: ` .field `
174- - Index: ` [0] `
175- - Slice: ` [0:5] `
176- - Filter: ` [?condition] `
177- - Multi-select: ` {key1: field1, key2: field2} `
178- - Pipe: ` expression | another `
292+ ## Function Categories Reference
293+
294+ | Category | Example Functions |
295+ | ----------| -------------------|
296+ | String | ` upper ` , ` lower ` , ` trim ` , ` split ` , ` snake_case ` , ` camel_case ` |
297+ | Array | ` unique ` , ` flatten ` , ` chunk ` , ` zip ` , ` intersection ` |
298+ | Object | ` keys ` , ` values ` , ` pick ` , ` omit ` , ` deep_merge ` |
299+ | Math | ` round ` , ` floor ` , ` ceil ` , ` sum ` , ` avg ` , ` stddev ` |
300+ | Type | ` type_of ` , ` is_array ` , ` is_string ` , ` to_boolean ` |
301+ | Utility | ` if ` , ` coalesce ` , ` default ` , ` now ` |
302+ | DateTime | ` format_date ` , ` time_ago ` , ` relative_time ` , ` is_weekend ` |
303+ | Duration | ` format_duration ` , ` parse_duration ` |
304+ | Network | ` is_private_ip ` , ` cidr_contains ` , ` ip_to_int ` |
305+ | Computing | ` format_bytes ` , ` parse_bytes ` , ` bit_and ` , ` bit_or ` |
306+ | Validation | ` is_email ` , ` is_uuid ` , ` is_ipv4 ` , ` is_url ` |
307+ | Encoding | ` base64_encode ` , ` base64_decode ` , ` url_encode ` |
308+ | Hash | ` md5 ` , ` sha256 ` , ` hmac_sha256 ` |
309+ | Regex | ` regex_match ` , ` regex_replace ` , ` regex_extract ` |
310+ | Semver | ` semver_compare ` , ` semver_satisfies ` , ` semver_parse ` |
311+ | Fuzzy | ` levenshtein ` , ` soundex ` , ` jaro_winkler ` |
312+ | JSON Patch | ` json_diff ` , ` json_patch ` , ` json_merge_patch ` |
313+
314+ For the complete list, see the [ jmespath-extensions documentation] ( https://docs.rs/jmespath_extensions ) .
315+
316+ ## JMESPath Syntax Reference
317+
318+ | Syntax | Description | Example |
319+ | --------| -------------| ---------|
320+ | ` 'value' ` | String literal | ` [?name=='cache'] ` |
321+ | `` `123` `` | Number literal | ` [?size > ` 1024` ] ` |
322+ | `` `true` `` | Boolean literal | ` [?active == ` true` ] ` |
323+ | ` @ ` | Current element | ` sort_by(@, &name) ` |
324+ | ` .field ` | Child access | ` cluster.name ` |
325+ | ` [0] ` | Index access | ` nodes[0] ` |
326+ | ` [0:5] ` | Slice | ` databases[:5] ` |
327+ | ` [?expr] ` | Filter | ` [?status=='active'] ` |
328+ | ` {k: v} ` | Multi-select | ` {id: uid, n: name} ` |
329+ | ` \| ` | Pipe | ` [].name \| sort(@) ` |
330+ | ` &field ` | Expression reference | ` sort_by(@, &name) ` |
179331
180332For full syntax, see [ jmespath.org] ( https://jmespath.org/ ) .
181333
0 commit comments