# jpx - JMESPath CLI with Extended Functions
[](https://crates.io/crates/jpx)
[](https://crates.io/crates/jpx)
[](https://github.com/joshrotenberg/jmespath-extensions#license)
A command-line tool for querying JSON data using JMESPath expressions with 189 additional functions beyond the standard JMESPath specification. Also includes the 26 standard JMESPath built-in functions.
## Installation
```bash
# Homebrew (macOS/Linux)
brew tap joshrotenberg/brew
brew install jpx
# Pre-built binaries (macOS, Linux, Windows)
# Download from https://github.com/joshrotenberg/jmespath-extensions/releases
# From crates.io
cargo install jpx
# From source
git clone https://github.com/joshrotenberg/jmespath-extensions
cd jmespath-extensions/jpx
cargo install --path .
```
## Usage
```bash
jpx [OPTIONS] [EXPRESSION]
Arguments:
[EXPRESSION] JMESPath expression to evaluate
Options:
-e, --expression <EXPR> Expression(s) to evaluate (can be chained)
-Q, --query-file <FILE> Read JMESPath expression from file
-f, --file <FILE> Input file (reads from stdin if not provided)
-r, --raw Output raw strings without quotes
-c, --compact Compact output (no pretty printing)
-n, --null-input Don't read input, use null as input value
-s, --slurp Read all inputs into an array
--color <MODE> Colorize output (auto, always, never)
-o, --output <FILE> Output file (writes to stdout if not provided)
-q, --quiet Suppress errors and warnings
-v, --verbose Show expression details and timing
--strict Strict mode - only standard JMESPath (no extensions)
--completions <SHELL> Generate shell completions (bash, zsh, fish, powershell)
--list-functions List all available extension functions
--list-category <NAME> List functions in a specific category
--describe <FUNCTION> Show detailed info for a specific function
-h, --help Print help
-V, --version Print version
```
## Environment Variables
Configure jpx defaults via environment variables (CLI flags take precedence):
| `JPX_VERBOSE=1` | Enable verbose mode |
| `JPX_QUIET=1` | Enable quiet mode |
| `JPX_STRICT=1` | Enable strict mode (standard JMESPath only) |
| `JPX_RAW=1` | Output raw strings without quotes |
| `JPX_COMPACT=1` | Compact output (no pretty printing) |
```bash
# Set defaults in your shell profile
export JPX_RAW=1 # Always output raw strings
# Temporarily use strict mode
JPX_STRICT=1 jpx 'length(@)' data.json
# Unset to use extensions again
unset JPX_STRICT
jpx 'upper(name)' data.json # Extension functions work
```
## Function Discovery
```bash
# List all available functions grouped by category
# Shows 26 standard JMESPath functions and 189 extension functions
jpx --list-functions
# List functions in a specific category
jpx --list-category string
jpx --list-category math
jpx --list-category geo
jpx --list-category standard # List all 26 standard JMESPath functions
# Get detailed info about a specific function
# Shows type (standard JMESPath or extension), category, signature, and example
jpx --describe upper
jpx --describe haversine_km
jpx --describe abs # Standard JMESPath function
```
## Examples
### Basic Queries
```bash
# Simple field access
# Array operations
# Nested access
```
### String Functions
```bash
# Case conversion
# String manipulation
```
### Array Functions
```bash
# Get unique values
# Chunk arrays
# Array statistics
```
### Date/Time Functions
```bash
# Current Unix timestamp
# Format a Unix timestamp
# Date arithmetic (add 7 days to timestamp)
```
### Duration Functions
```bash
# Parse human-readable durations
# Format seconds as duration
```
### Color Functions
```bash
# Convert colors
# Color manipulation
```
### Computing Functions
```bash
# Parse byte sizes
# Format bytes
# Bitwise operations
```
### Hash and Encoding Functions
```bash
# Hash functions
# Base64 encoding
# URL encoding
```
### Geo Functions
```bash
# Calculate distance between coordinates (km)
# Calculate bearing
```
### Network Functions
```bash
# IP address operations
```
### Semver Functions
```bash
# Parse semantic versions
# Compare versions
# Check version constraints
```
### Text Analysis Functions
```bash
# Word and character counts
# Reading time estimation
# Word frequencies
```
### Phonetic Functions
```bash
# Soundex encoding
# Check if names sound alike
# Double Metaphone
```
### Fuzzy Matching Functions
```bash
# Levenshtein distance
# Jaro-Winkler similarity
# Sorensen-Dice coefficient
```
### ID Generation Functions
```bash
# Generate UUIDs
# Generate nanoids
# Generate ULIDs
```
### Validation Functions
```bash
# Email validation
# URL validation
# UUID validation
# IP address validation
```
### Expression Functions (Higher-Order)
```bash
# Filter with expression (expression string first, then array)
echo '[{"name": "Alice"}, {"name": "Bob"}]' | jpx 'map_expr(`"name"`, @)'
# ["Alice", "Bob"]
# Group by expression
```
## Using Test Data Files
The `testdata/` directory contains sample JSON files for experimenting:
```bash
# Users data
jpx -f testdata/users.json '[].name'
jpx -f testdata/users.json 'filter_expr(@, &age > `25`) | [].name'
# Server logs
jpx -f testdata/servers.json 'filter_expr(@, &status == `active`) | length(@)'
jpx -f testdata/servers.json '[].{name: name, uptime: format_duration(uptime_seconds)}'
# E-commerce orders
jpx -f testdata/orders.json 'sum([].total)'
jpx -f testdata/orders.json 'group_by_expr(@, &status)'
# Geo locations
jpx -f testdata/locations.json 'haversine_km([0].lat, [0].lon, [1].lat, [1].lon)'
# Versions
jpx -f testdata/packages.json 'sort_by_expr(@, &semver_parse(version).major)'
```
## Using Query Files
For complex queries, you can store the JMESPath expression in a file and use `-Q` / `--query-file`:
```bash
# Create a query file
cat > transform.jmespath << 'EOF'
{
users: @[?active].{
name: name,
email: contact.email,
joined: format_date(created_at, '%Y-%m-%d')
},
total: length(@[?active]),
generated: now()
}
EOF
# Run the query
jpx -Q transform.jmespath -f users.json
```
Benefits of query files:
- Easier to write and edit complex expressions
- Can be version controlled
- Reusable across different data files
- No shell escaping issues
See the `queries/` directory for example query files.
## Tips
- Use `-r` (raw) when piping string output to other commands
- Use `-c` (compact) for single-line JSON output
- Use `--list-functions` to see all available functions
- Backticks create literal values: `` `5` `` is number 5, `` `"hello"` `` is string
- Use `&` prefix for expression references in higher-order functions
## License
MIT OR Apache-2.0