# 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 320+ additional functions beyond the standard JMESPath specification.
Built on the [`jmespath`](https://crates.io/crates/jmespath) crate by [@mtdowling](https://github.com/mtdowling), which provides the complete Rust implementation of the [JMESPath specification](https://jmespath.org/specification.html) including parsing, evaluation, and all 26 standard 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 .
# With MCP server support
cargo install --path . --features mcp
```
## MCP Server (AI Assistant Integration)
jpx can run as an [MCP (Model Context Protocol)](https://modelcontextprotocol.io/) server, allowing AI assistants like Claude to use JMESPath for JSON querying and transformation.
### Building with MCP Support
```bash
cargo build -p jpx --features mcp --release
```
### Running the Server
```bash
jpx mcp
```
### MCP Tools
| `evaluate` | Run JMESPath expressions against JSON input |
| `evaluate_file` | Query JSON files directly from disk (with security checks) |
| `batch_evaluate` | Run multiple expressions against the same input |
| `format` | Pretty-print JSON with configurable indentation |
| `diff` | Generate RFC 6902 JSON Patch between two documents |
| `patch` | Apply RFC 6902 JSON Patch operations |
| `merge` | Apply RFC 7396 JSON Merge Patch |
| `keys` | Extract object keys (optionally recursive with dot notation) |
| `functions` | List available functions (with optional category filter) |
| `describe` | Get detailed info for a specific function |
| `categories` | List all function categories |
| `validate` | Check expression syntax without executing |
### Claude Desktop Configuration
Add to `~/Library/Application Support/Claude/claude_desktop_config.json` (macOS) or `%APPDATA%\Claude\claude_desktop_config.json` (Windows):
```json
{
"mcpServers": {
"jpx": {
"command": "/path/to/jpx",
"args": ["mcp"]
}
}
}
```
### Example Usage
Once configured, Claude can use jpx to query JSON data:
```
User: I have this JSON: {"users": [{"name": "alice", "age": 30}, {"name": "bob", "age": 25}]}
Get the names of users over 28.
Claude: [Uses jpx.evaluate with expression "users[?age > `28`].name"]
Result: ["alice"]
```
#### More MCP Examples
**Query a file directly:**
```
Claude: [Uses jpx.evaluate_file with file_path="/data/users.json", expression="users[*].email"]
```
**Batch multiple queries:**
```
Claude: [Uses jpx.batch_evaluate with input and expressions=["length(users)", "users[0].name", "max(users[*].age)"]]
Result: {results: [{expression: "length(users)", result: 10}, ...]}
```
**Compare JSON documents (RFC 6902):**
```
Claude: [Uses jpx.diff with source and target documents]
Result: [{"op": "replace", "path": "/name", "value": "bob"}, {"op": "add", "path": "/age", "value": 30}]
```
**Explore JSON structure:**
```
Claude: [Uses jpx.keys with input and recursive=true]
Result: ["user", "user.name", "user.profile", "user.profile.settings"]
```
## 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 320+ 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