§JMESPath Extensions
A comprehensive collection of 150+ extension functions for JMESPath queries.
§Built on jmespath.rs
This crate extends the jmespath crate by
@mtdowling, which provides the complete Rust implementation
of the JMESPath specification. All spec-compliant
parsing, evaluation, and the 26 built-in functions come from that foundational library—we
simply add extra functions on top.
If you only need standard JMESPath functionality, use jmespath directly.
§Non-Standard Extension Warning
These functions are NOT part of the JMESPath specification.
Queries using these extension functions will NOT work in other JMESPath
implementations (Python, JavaScript, Go, etc.). If you need portable queries,
use only the 26 standard JMESPath built-in functions:
abs, avg, ceil, contains, ends_with, floor, join, keys,
length, map, max, max_by, merge, min, min_by, not_null,
reverse, sort, sort_by, starts_with, sum, to_array, to_number,
to_string, type, values
These extensions are useful when:
- You control both the query author and the runtime environment
- You need functionality beyond standard JMESPath
- Cross-implementation compatibility is not required
§JEP Alignment
Some functions in this library align with JMESPath Enhancement Proposals (JEPs),
which are draft specifications for extending JMESPath. While JEPs are not yet part of the
official specification, aligning with them improves compatibility with other implementations
that adopt the same proposals.
§JEP-013: Object Manipulation Functions
The following functions implement JEP-013:
| Function | Signature | Description |
items | items(object) → array[array] | Returns [[key, value], ...] pairs |
from_items | from_items(array) → object | Converts [[key, value], ...] to object |
zip | zip(array1, array2) → array | Zips two arrays into pairs |
§JEP-014: String Functions
The following functions implement JEP-014:
| Function | Signature | Description |
find_first | find_first(string, sub, start?, end?) → number|null | Find first occurrence |
find_last | find_last(string, sub, start?, end?) → number|null | Find last occurrence |
lower | lower(string) → string | Convert to lowercase |
upper | upper(string) → string | Convert to uppercase |
trim | trim(string, chars?) → string | Remove leading/trailing chars |
trim_left | trim_left(string, chars?) → string | Remove leading chars |
trim_right | trim_right(string, chars?) → string | Remove trailing chars |
pad_left | pad_left(string, width, pad?) → string | Left-pad to width |
pad_right | pad_right(string, width, pad?) → string | Right-pad to width |
replace | replace(string, old, new, count?) → string | Replace occurrences |
split | split(string, sep, count?) → array | Split into array |
Note: Some JEP-014 functions in this library have slight signature differences
(e.g., required vs optional parameters). See individual function documentation for details.
§Quick Start
use jmespath::{Runtime, Variable};
use jmespath_extensions::register_all;
let mut runtime = Runtime::new();
runtime.register_builtin_functions();
register_all(&mut runtime);
let expr = runtime.compile("upper(@)").unwrap();
let data = Variable::String("hello".to_string());
let result = expr.search(&data).unwrap();
assert_eq!(result.as_string().unwrap(), "HELLO");
§Working with JSON Data
Most real-world usage involves querying JSON data:
use jmespath::{Runtime, Variable};
use jmespath_extensions::register_all;
let mut runtime = Runtime::new();
runtime.register_builtin_functions();
register_all(&mut runtime);
let json = r#"{
"users": [
{"name": "alice", "email": "ALICE@EXAMPLE.COM"},
{"name": "bob", "email": "BOB@EXAMPLE.COM"}
]
}"#;
let data = Variable::from_json(json).unwrap();
let expr = runtime.compile("users[*].{name: upper(name), email: lower(email)}").unwrap();
let result = expr.search(&data).unwrap();
§Feature Flags
This crate uses feature flags to control which functions are included.
This allows you to minimize dependencies and binary size.
| Feature | Dependencies | Description |
full (default) | all | All functions |
core | none | String, array, object, math, type, utility, path |
string | none | String manipulation |
array | none | Array operations |
object | none | Object utilities |
math | none | Mathematical operations |
type | none | Type conversion and checking |
utility | none | Utility functions |
path | none | Path manipulation |
validation | none | Validation functions |
hash | md-5, sha1, sha2, crc32fast | Hash functions |
encoding | base64, hex | Encoding functions |
url | url | URL functions |
regex | regex | Regex functions |
uuid | uuid | UUID generation |
rand | rand | Random functions |
datetime | chrono | Date/time functions |
fuzzy | strsim | Fuzzy matching functions |
expression | none | Expression-based functions |
phonetic | rphonetic | Phonetic encoding functions |
geo | geoutils | Geospatial functions |
semver | semver | Semantic versioning |
network | ipnetwork | Network/IP functions |
ids | nanoid, ulid | ID generation |
text | none | Text analysis |
duration | none | Duration parsing |
color | none | Color manipulation |
computing | none | Computing utilities |
jsonpatch | json-patch | JSON Patch functions |
multi-match | aho-corasick | Multi-pattern matching |
§Using Specific Features
# Only include string and array functions (no external dependencies)
[dependencies]
jmespath_extensions = { version = "0.1", default-features = false, features = ["string", "array"] }
# Include core functions plus regex
[dependencies]
jmespath_extensions = { version = "0.1", default-features = false, features = ["core", "regex"] }
§Module Overview
See each module’s documentation for detailed function reference with examples:
string - String manipulation (upper, lower, split, replace, camel_case, etc.)
array - Array operations (first, last, unique, chunk, zip, range, etc.)
object - Object utilities (items, pick, omit, deep_merge, etc.)
math - Math operations (round, sqrt, pow, median, sin, cos, etc.)
type_conv - Type functions (type_of, is_string, is_empty, to_number, etc.)
utility - Utilities (default, if, coalesce, json_encode, etc.)
datetime - Date/time (now, now_millis, parse_date, format_date, date_add, date_diff)
fuzzy - Fuzzy matching (levenshtein, jaro_winkler, sorensen_dice, etc.)
expression - Expression functions (map_expr, filter_expr, any_expr, all_expr, find_expr, sort_by_expr)
path - Path functions (path_basename, path_dirname, path_ext, path_join)
validation - Validation (is_email, is_url, is_uuid, is_ipv4, is_ipv6)
hash - Hashing (md5, sha1, sha256, crc32)
encoding - Encoding (base64_encode, base64_decode, hex_encode, hex_decode)
url_fns - URL functions (url_encode, url_decode, url_parse)
regex_fns - Regex (regex_match, regex_extract, regex_replace)
random - Random (random, shuffle, sample, uuid)
phonetic - Phonetic encoding (soundex, metaphone, double_metaphone, nysiis, sounds_like)
geo - Geospatial (haversine, haversine_km, haversine_mi, bearing)
semver_fns - Semantic versioning (semver_parse, semver_compare, semver_matches, is_semver)
network - Network/IP (ip_to_int, int_to_ip, cidr_contains, cidr_network, is_private_ip)
ids - ID generation (nanoid, ulid, ulid_timestamp)
text - Text analysis (word_count, char_count, reading_time, word_frequencies)
duration - Duration parsing (parse_duration, format_duration)
color - Color manipulation (hex_to_rgb, rgb_to_hex, lighten, darken, color_mix)
computing - Computing utilities (parse_bytes, format_bytes, bit_and, bit_or, bit_xor)
jsonpatch - JSON Patch (RFC 6902) and Merge Patch (RFC 7396) (json_patch, json_merge_patch, json_diff)
§Quick Reference (335 functions)
Click any function name to jump to its detailed documentation in the functions module.
| Function | Signature | Description |
chunk | array, number -> array | Split array into chunks of size n |
compact | array -> array | Remove null values from array |
difference | array, array -> array | Elements in first array not in second |
drop | array, number -> array | Drop first n elements |
find_index | array, any -> number | null | Find index of value in array |
first | array -> any | Get first element of array |
flatten | array -> array | Flatten array one level deep |
flatten_deep | array -> array | Recursively flatten nested arrays |
frequencies | array -> object | Count occurrences of each value |
group_by | array, string -> object | Group array elements by key |
includes | array, any -> boolean | Check if array contains value |
index_at | array, number -> any | Get element at index (supports negative) |
intersection | array, array -> array | Elements common to both arrays |
last | array -> any | Get last element of array |
pairwise | array -> array | Return adjacent pairs from array |
range | number, number -> array | Generate array of numbers |
sliding_window | array, number -> array | Create overlapping windows of size n (alias for window) |
take | array, number -> array | Take first n elements |
transpose | array -> array | Transpose a 2D array (swap rows and columns) |
union | array, array -> array | Unique elements from both arrays |
unique | array -> array | Remove duplicate values |
zip | array, array -> array | Zip two arrays together |
| Function | Signature | Description |
color_complement | string -> string | Get complementary color |
color_grayscale | string -> string | Convert to grayscale |
color_invert | string -> string | Invert a color |
color_mix | string, string, number -> string | Mix two colors |
darken | string, number -> string | Darken a color by percentage |
hex_to_rgb | string -> object | Convert hex color to RGB |
lighten | string, number -> string | Lighten a color by percentage |
rgb_to_hex | number, number, number -> string | Convert RGB to hex color |
| Function | Signature | Description |
business_days_between | number, number -> number | Count business days (weekdays) between two timestamps |
date_add | number, number, string -> number | Add time to timestamp |
date_diff | number, number, string -> number | Difference between timestamps |
duration_since | number|string -> object | Get detailed duration object from timestamp to now |
end_of_day | number|string -> string | Get ISO 8601 string for end of day (23:59:59) |
epoch_ms | -> number | Current Unix timestamp in milliseconds (alias for now_ms) |
format_date | number, string -> string | Format timestamp to string |
from_epoch | number -> string | Convert Unix timestamp (seconds) to ISO 8601 string |
from_epoch_ms | number -> string | Convert Unix timestamp (milliseconds) to ISO 8601 string |
is_after | number|string, number|string -> boolean | Check if first date is after second date (accepts timestamps or date strings) |
is_before | number|string, number|string -> boolean | Check if first date is before second date (accepts timestamps or date strings) |
is_between | number|string, number|string, number|string -> boolean | Check if date is between start and end (inclusive, accepts timestamps or date strings) |
is_same_day | number|string, number|string -> boolean | Check if two timestamps/dates are on the same day |
is_weekday | number -> boolean | Check if timestamp falls on weekday (Monday-Friday) |
is_weekend | number -> boolean | Check if timestamp falls on weekend (Saturday or Sunday) |
parse_date | string, string? -> number | Parse date string to timestamp |
quarter | number -> number | Get quarter of year (1-4) from timestamp |
relative_time | number -> string | Human-readable relative time from timestamp |
start_of_day | number|string -> string | Get ISO 8601 string for start of day (00:00:00) |
start_of_month | number|string -> string | Get ISO 8601 string for start of month |
start_of_week | number|string -> string | Get ISO 8601 string for start of week (Monday 00:00:00) |
start_of_year | number|string -> string | Get ISO 8601 string for start of year |
time_ago | number|string -> string | Human-readable time since date (accepts timestamps or date strings) |
timezone_convert | string, string, string -> string | Convert timestamp between timezones (IANA timezone names) |
to_epoch | number|string -> number | Convert date string or timestamp to Unix timestamp (seconds) |
to_epoch_ms | number|string -> number | Convert date string or timestamp to Unix timestamp (milliseconds) |
| Function | Signature | Description |
base64_decode | string -> string | Decode base64 string |
base64_encode | string -> string | Encode string to base64 |
hex_decode | string -> string | Decode hex string |
hex_encode | string -> string | Encode string to hex |
jwt_decode | string -> object | Decode JWT payload (claims) without verification |
jwt_header | string -> object | Decode JWT header without verification |
html_escape | string -> string | Escape HTML special characters |
html_unescape | string -> string | Unescape HTML entities |
| Function | Signature | Description |
all_expr | array, expression -> boolean | Return true if every element satisfies the expression (short-circuits on false) |
any_expr | array, expression -> boolean | Return true if any element satisfies the expression (short-circuits) |
apply | object|string, ...any -> any | Apply a partial function or invoke a function by name with arguments |
count_by | string, array -> object | Count occurrences grouped by expression result |
count_expr | array, expression -> number | Count how many elements satisfy the expression |
drop_while | string, array -> array | Drop elements from array while expression is truthy |
every | string, array -> boolean | Check if all elements match (alias for all_expr) |
filter_expr | array, expression -> array | Keep elements where JMESPath expression evaluates to truthy value |
find_expr | array, expression -> any | Return first element where expression is truthy, or null if none match |
find_index_expr | array, expression -> number | null | Return zero-based index of first matching element, or -1 if none match |
flat_map_expr | array, expression -> array | Apply expression to each element and flatten all results into one array |
group_by_expr | array, expression -> object | Group elements into object keyed by expression result |
map_expr | array, expression -> array | Apply a JMESPath expression to each element, returning transformed array |
map_keys | string, object -> object | Transform object keys using expression |
map_values | string, object -> object | Transform object values using expression |
max_by_expr | array, expression -> any | Return element with largest expression result, or null for empty array |
min_by_expr | array, expression -> any | Return element with smallest expression result, or null for empty array |
order_by | array, array[[string, string]] -> array | Sort array by multiple fields with ascending/descending control |
partial | string, ...any -> object | Create a partial function with some arguments pre-filled |
partition_expr | array, expression -> array | Split array into [matches, non-matches] based on expression |
reduce_expr | string, array, any -> any | Reduce array to single value using accumulator expression |
reject | string, array -> array | Keep elements where expression is falsy (inverse of filter_expr) |
scan_expr | string, array, any -> array | Like reduce but returns array of intermediate accumulator values |
some | string, array -> boolean | Check if any element matches (alias for any_expr) |
sort_by_expr | array, expression -> array | Sort array by expression result in ascending order |
take_while | string, array -> array | Take elements from array while expression is truthy |
unique_by_expr | array, expression -> array | Remove duplicates by expression result, keeping first occurrence |
zip_with | string, array, array -> array | Zip two arrays with a custom combiner expression |
walk | string, any -> any | Recursively apply expression to all components of a value (bottom-up) |
| Function | Signature | Description |
to_csv | array -> string | Convert array to CSV row string (RFC 4180 compliant) |
to_tsv | array -> string | Convert array to TSV row string (tab-separated) |
to_csv_rows | array -> string | Convert array of arrays to multi-line CSV string |
to_csv_table | array, array? -> string | Convert array of objects to CSV with header row |
| Function | Signature | Description |
damerau_levenshtein | string, string -> number | Damerau-Levenshtein distance |
jaro | string, string -> number | Jaro similarity (0-1) |
jaro_winkler | string, string -> number | Jaro-Winkler similarity (0-1) |
levenshtein | string, string -> number | Levenshtein edit distance |
normalized_levenshtein | string, string -> number | Normalized Levenshtein (0-1) |
sorensen_dice | string, string -> number | Sorensen-Dice coefficient (0-1) |
| Function | Signature | Description |
geo_bearing | number, number, number, number -> number | Bearing between coordinates |
geo_distance | number, number, number, number -> number | Haversine distance in meters |
geo_distance_km | number, number, number, number -> number | Haversine distance in kilometers |
geo_distance_miles | number, number, number, number -> number | Haversine distance in miles |
| Function | Signature | Description |
crc32 | string -> number | Calculate CRC32 checksum |
hmac_md5 | string, string -> string | Calculate HMAC-MD5 signature |
hmac_sha1 | string, string -> string | Calculate HMAC-SHA1 signature |
hmac_sha256 | string, string -> string | Calculate HMAC-SHA256 signature |
hmac_sha512 | string, string -> string | Calculate HMAC-SHA512 signature |
md5 | string -> string | Calculate MD5 hash |
sha1 | string -> string | Calculate SHA-1 hash |
sha256 | string -> string | Calculate SHA-256 hash |
sha512 | string -> string | Calculate SHA-512 hash |
| Function | Signature | Description |
nanoid | number? -> string | Generate nanoid |
ulid | -> string | Generate ULID |
ulid_timestamp | string -> number | Extract timestamp from ULID |
| Function | Signature | Description |
json_diff | object, object -> array | Generate JSON Patch (RFC 6902) that transforms first object into second |
json_merge_patch | object, object -> object | Apply JSON Merge Patch (RFC 7396) to an object |
json_patch | object, array -> object | Apply JSON Patch (RFC 6902) operations to an object |
| Function | Signature | Description |
abs_fn | number -> number | Absolute value |
add | number, number -> number | Add two numbers |
ceil_fn | number -> number | Round up to nearest integer |
clamp | number, number, number -> number | Clamp value to range |
cos | number -> number | Cosine function |
covariance | array, array -> number | Covariance between two arrays |
divide | number, number -> number | Divide first number by second |
ewma | array, number -> array | Exponential weighted moving average |
floor_fn | number -> number | Round down to nearest integer |
format_number | number, number?, string? -> string | Format number with separators and optional suffix |
log | number -> number | Natural logarithm |
median | array -> number | Calculate median of array |
mod_fn | number, number -> number | Modulo operation |
mode | array -> any | Find the most common value in an array |
moving_avg | array, number -> array | Simple moving average with window size |
multiply | number, number -> number | Multiply two numbers |
percentile | array, number -> number | Calculate percentile of array |
pow | number, number -> number | Raise to power |
quantile | array, number -> number | Nth quantile (generalized percentile, q in [0,1]) |
round | number, number -> number | Round to specified decimal places |
sin | number -> number | Sine function |
sqrt | number -> number | Square root |
standardize | array -> array | Standardize array to mean=0, std=1 (z-score normalization) |
stddev | array -> number | Calculate standard deviation of array |
subtract | number, number -> number | Subtract second number from first |
tan | number -> number | Tangent function |
to_fixed | number, number -> string | Format number with exact decimal places |
variance | array -> number | Calculate variance of array |
| Function | Signature | Description |
extract_all | string, array[string] -> array[object] | Extract all pattern matches with positions (Aho-Corasick) |
extract_between | string, string, string -> string|null | Extract text between two delimiters |
match_all | string, array[string] -> boolean | Check if string contains all of the patterns (Aho-Corasick) |
match_any | string, array[string] -> boolean | Check if string contains any of the patterns (Aho-Corasick) |
match_count | string, array[string] -> number | Count total pattern matches in string (Aho-Corasick) |
match_positions | string, array[string] -> array[object] | Get start/end positions of all pattern matches (Aho-Corasick) |
match_which | string, array[string] -> array[string] | Return array of patterns that match the string (Aho-Corasick) |
replace_many | string, object -> string | Replace multiple patterns simultaneously (Aho-Corasick) |
split_keep | string, string -> array[string] | Split string keeping delimiters in result |
tokenize | string, object? -> array[string] | Smart word tokenization with optional lowercase and min_length |
| Function | Signature | Description |
cidr_broadcast | string -> string | Get broadcast address from CIDR |
cidr_contains | string, string -> boolean | Check if IP is in CIDR range |
cidr_network | string -> string | Get network address from CIDR |
cidr_prefix | string -> number | Get prefix length from CIDR |
int_to_ip | number -> string | Convert integer to IP address |
ip_to_int | string -> number | Convert IP address to integer |
is_private_ip | string -> boolean | Check if IP is in private range |
| Function | Signature | Description |
deep_diff | object, object -> object | Structural diff between two objects |
deep_equals | any, any -> boolean | Deep equality check for any two values |
deep_merge | object, object -> object | Recursively merge objects |
defaults | object, object -> object | Assign default values for missing keys (shallow) |
defaults_deep | object, object -> object | Recursively assign default values for missing keys |
delete_path | any, string -> any | Delete value at JSON pointer path (immutable) |
flatten_keys | object -> object | Flatten nested object with dot notation keys |
from_items | array -> object | Convert array of [key, value] pairs to object |
get | any, string, any? -> any | Get value at dot-separated path with optional default |
has | any, string -> boolean | Check if dot-separated path exists |
invert | object -> object | Swap keys and values |
items | object -> array | Convert object to array of [key, value] pairs |
leaves | any -> array | Get all leaf values (non-object, non-array) |
leaves_with_paths | any -> array | Get all leaf values with their JSON pointer paths |
omit | object, array -> object | Remove specific keys from object |
paths | any -> array | List all JSON pointer paths in value |
pick | object, array -> object | Select specific keys from object |
rename_keys | object, object -> object | Rename object keys |
set_path | any, string, any -> any | Set value at JSON pointer path (immutable) |
| Function | Signature | Description |
path_basename | string -> string | Get filename from path |
path_dirname | string -> string | Get directory from path |
path_ext | string -> string | Get file extension |
path_join | string... -> string | Join path segments |
| Function | Signature | Description |
caverphone | string -> string | Caverphone code |
caverphone2 | string -> string | Caverphone 2 code |
double_metaphone | string -> object | Double Metaphone codes |
match_rating_codex | string -> string | Match Rating codex |
metaphone | string -> string | Metaphone phonetic code |
nysiis | string -> string | NYSIIS phonetic code |
phonetic_match | string, string, string -> boolean | Check phonetic match with algorithm |
soundex | string -> string | Soundex phonetic code |
sounds_like | string, string -> boolean | Check if strings sound similar |
| Function | Signature | Description |
random | -> number | Generate random number between 0 and 1 |
sample | array, number -> array | Random sample from array |
shuffle | array -> array | Randomly shuffle array |
| Function | Signature | Description |
regex_extract | string, string -> array | Extract regex matches |
regex_match | string, string -> boolean | Test if string matches regex |
regex_replace | string, string, string -> string | Replace regex matches |
| Function | Signature | Description |
abs | number -> number | Returns the absolute value of a number |
avg | array[number] -> number | Returns the average of an array of numbers |
ceil | number -> number | Returns the smallest integer greater than or equal to the number |
contains | array|string, any -> boolean | Returns true if the subject contains the search value |
ends_with | string, string -> boolean | Returns true if the subject ends with the suffix |
floor | number -> number | Returns the largest integer less than or equal to the number |
join | string, array[string] -> string | Returns array elements joined into a string with a separator |
keys | object -> array[string] | Returns an array of keys from an object |
length | array|object|string -> number | Returns the length of an array, object, or string |
map | expression, array -> array | Applies an expression to each element of an array |
max | array[number]|array[string] -> number|string | Returns the maximum value in an array |
max_by | array, expression -> any | Returns the element with maximum value by expression |
merge | object... -> object | Merges objects into a single object |
min | array[number]|array[string] -> number|string | Returns the minimum value in an array |
min_by | array, expression -> any | Returns the element with minimum value by expression |
not_null | any... -> any | Returns the first non-null argument |
reverse | array|string -> array|string | Reverses an array or string |
sort | array[number]|array[string] -> array | Sorts an array of numbers or strings |
sort_by | array, expression -> array | Sorts an array by expression result |
starts_with | string, string -> boolean | Returns true if the subject starts with the prefix |
sum | array[number] -> number | Returns the sum of an array of numbers |
to_array | any -> array | Converts a value to an array |
to_number | any -> number | Converts a value to a number |
to_string | any -> string | Converts a value to a string |
type | any -> string | Returns the type of a value as a string |
values | object -> array | Returns an array of values from an object |
| Function | Signature | Description |
abbreviate | string, number, string? -> string | Truncate string with ellipsis suffix |
camel_case | string -> string | Convert to camelCase |
capitalize | string -> string | Capitalize the first character |
center | string, number, string? -> string | Center-pad string to given width |
concat | string... -> string | Concatenate strings |
explode | string -> array | Convert a string to an array of Unicode codepoints |
find_first | string, string -> number | null | Find first occurrence of substring |
find_last | string, string -> number | null | Find last occurrence of substring |
indices | string, string -> array | Find all indices of substring occurrences |
implode | array -> string | Convert an array of Unicode codepoints to a string |
inside | string, string -> boolean | Check if search string is contained in string |
is_blank | string -> boolean | Check if string is empty or whitespace-only |
kebab_case | string -> string | Convert to kebab-case |
lower | string -> string | Convert string to lowercase |
ltrimstr | string, string -> string | Remove prefix from string if present |
mask | string, number?, string? -> string | Mask string, keeping last N characters visible |
normalize_whitespace | string -> string | Collapse multiple whitespace to single space |
pad_left | string, number, string -> string | Pad string on the left to reach target length |
pad_right | string, number, string -> string | Pad string on the right to reach target length |
redact | string, string, string? -> string | Redact regex pattern matches with replacement |
repeat | string, number -> string | Repeat a string n times |
replace | string, string, string -> string | Replace occurrences of a substring |
reverse_string | string -> string | Reverse a string |
rtrimstr | string, string -> string | Remove suffix from string if present |
slice | string, number, number -> string | Extract substring by start and end index |
snake_case | string -> string | Convert to snake_case |
split | string, string -> array | Split string by delimiter |
sprintf | string, any... -> string | Printf-style string formatting |
substr | string, number, number -> string | Extract substring by start index and length |
title | string -> string | Convert to title case |
trim | string -> string | Remove leading and trailing whitespace |
trim_left | string -> string | Remove leading whitespace |
trim_right | string -> string | Remove trailing whitespace |
upper | string -> string | Convert string to uppercase |
wrap | string, number -> string | Wrap text to specified width |
| Function | Signature | Description |
is_array | any -> boolean | Check if value is an array |
is_boolean | any -> boolean | Check if value is a boolean |
is_empty | any -> boolean | Check if value is empty |
is_null | any -> boolean | Check if value is null |
is_number | any -> boolean | Check if value is a number |
is_object | any -> boolean | Check if value is an object |
is_string | any -> boolean | Check if value is a string |
to_boolean | any -> boolean | Convert value to boolean |
type_of | any -> string | Get the type of a value |
| Function | Signature | Description |
url_decode | string -> string | URL decode a string |
url_encode | string -> string | URL encode a string |
url_parse | string -> object | Parse URL into components |
| Function | Signature | Description |
coalesce | any... -> any | Return first non-null value |
default | any, any -> any | Return default value if null |
if | boolean, any, any -> any | Conditional expression |
json_decode | string -> any | Parse JSON string |
json_encode | any -> string | Serialize value to JSON string |
json_pointer | any, string -> any | Access value using JSON Pointer (RFC 6901) |
now | -> number | Current Unix timestamp in seconds |
now_ms | -> number | Current Unix timestamp in milliseconds |
pretty | any, number? -> string | Pretty-print value as formatted JSON string |
env | -> object | Get all environment variables as an object |
get_env | string -> string | null | Get a single environment variable by name |
| Function | Signature | Description |
uuid | -> string | Generate a UUID v4 |
| Function | Signature | Description |
is_base64 | string -> boolean | Check if valid Base64 encoding |
is_credit_card | string -> boolean | Validate credit card number (Luhn check + length) |
is_email | string -> boolean | Validate email address format |
is_hex | string -> boolean | Check if valid hexadecimal string |
is_ipv4 | string -> boolean | Validate IPv4 address format |
is_ipv6 | string -> boolean | Validate IPv6 address format |
is_iso_date | string -> boolean | Validate ISO 8601 date format |
is_json | string -> boolean | Check if string is valid JSON |
is_jwt | string -> boolean | Check if valid JWT structure (3 base64url parts) |
is_phone | string -> boolean | Validate phone number format |
is_url | string -> boolean | Validate URL format |
is_uuid | string -> boolean | Validate UUID format |
luhn_check | string -> boolean | Generic Luhn algorithm check |
§Error Handling
Extension functions follow JMESPath conventions:
- Type errors return an error (e.g., passing a number to
upper)
- Invalid operations return null (e.g.,
index_at with out-of-bounds index)
use jmespath::{Runtime, Variable};
use jmespath_extensions::register_all;
let mut runtime = Runtime::new();
runtime.register_builtin_functions();
register_all(&mut runtime);
let expr = runtime.compile("upper(@)").unwrap();
let data = Variable::Number(serde_json::Number::from(42));
assert!(expr.search(&data).is_err());
let expr = runtime.compile("index_at(@, `10`)").unwrap();
let data = Variable::from_json("[1, 2, 3]").unwrap();
let result = expr.search(&data).unwrap();
assert!(result.is_null());