JSON query and transform CLI - simpler than jq
Project description
jsonx
JSON query and transform CLI — simpler than jq.
Installation
pip install jsonx-cli
For JSON Schema validation:
pip install jsonx-cli[schema]
Quick Start
# Get a nested value
jsonx get .users[0].name data.json
# From stdin
cat data.json | jsonx get .config.debug
# Set a value
jsonx set .config.debug true data.json
# List all keys
jsonx keys data.json
# Pretty print
jsonx format data.json
Path Syntax
jsonx uses simple dot notation:
| Pattern | Meaning |
|---|---|
.key |
Object property |
.nested.key |
Nested property |
[0] |
Array index |
[-1] |
Last array item |
[*] |
All array items |
[0:3] |
Array slice |
Examples:
jsonx get .name data.json # Get "name" property
jsonx get .users[0] data.json # First user
jsonx get .users[-1] data.json # Last user
jsonx get .users[*].email data.json # All user emails
jsonx get .items[0:5] data.json # First 5 items
Commands
get - Extract values
jsonx get .path [file] # Extract value at path
jsonx get .path file --raw # Raw output (no quotes)
jsonx get .path file --json # Force JSON output
set - Modify values
jsonx set .path value [file] # Set and output
jsonx set .path value file -i # Modify in place
jsonx set .path value file -o out.json # Write to file
Value is parsed as JSON:
jsonx set .debug true data.json # boolean
jsonx set .count 42 data.json # number
jsonx set .name '"Alice"' data.json # string (note quotes)
jsonx set .tags '["a","b"]' data.json # array
del - Delete values
jsonx del .path [file] # Delete and output
jsonx del .path file -i # Delete in place
keys - List keys
jsonx keys [file] # Top-level keys
jsonx keys file -r # All keys recursively
flatten / unflatten - Structure transformation
# Flatten nested structure
jsonx flatten data.json
# {"users[0].name": "Alice", "config.debug": true}
# Unflatten back
echo '{"user.name": "Alice"}' | jsonx unflatten
# {"user": {"name": "Alice"}}
merge - Combine files
jsonx merge base.json override.json # Deep merge
jsonx merge a.json b.json --shallow # Shallow merge
diff - Compare files
jsonx diff old.json new.json
# + config.newKey: "value" (green - added)
# - config.removed: true (red - removed)
# ~ config.changed: 1 → 2 (yellow - changed)
format / minify - Pretty print
jsonx format data.json # Pretty print
jsonx format data.json -i 4 # 4-space indent
jsonx minify data.json # Compact
validate - JSON Schema
jsonx validate data.json schema.json
# ✓ Valid
# or
# ✗ Invalid: 'email' is required
type - Show value type
echo '[]' | jsonx type # array
echo '{}' | jsonx type # object
echo '42' | jsonx type # integer
count - Count items
jsonx count data.json # Top-level count
jsonx get .users data.json | jsonx count # Count array items
each - Iterate arrays
# Output each item as JSON
jsonx each data.json -p .users
# With template
jsonx each data.json -p .users -t '{.name}: {.email}'
Piping
jsonx works great in pipelines:
# Extract, transform, merge
cat config.json | jsonx get .database | jsonx set .host '"prod.db"'
# Count users
jsonx get .users data.json | jsonx count
# Extract all emails
jsonx get .users[*].email data.json
# Filter and format
curl api/data | jsonx get .results | jsonx format
For AI Agents
See SKILL.md for agent-optimized documentation.
Exit Codes
0- Success1- Error (invalid JSON, path not found, etc.)
License
MIT
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
jsonx_cli-0.1.0.tar.gz
(9.9 kB
view details)
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
jsonx_cli-0.1.0-py3-none-any.whl
(10.6 kB
view details)
File details
Details for the file jsonx_cli-0.1.0.tar.gz.
File metadata
- Download URL: jsonx_cli-0.1.0.tar.gz
- Upload date:
- Size: 9.9 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.2.0 CPython/3.12.12
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
a05dee79c34ef5649c8d12df1b097ed22f7b8ecfb65836d7d98c52db6d5a0c32
|
|
| MD5 |
28713fcde7136b422f702a829c4e8eb7
|
|
| BLAKE2b-256 |
caf69a73186297aa191a540ff86ec0d93b286c4bfc19c6c2bde4cfb9a37387e1
|
File details
Details for the file jsonx_cli-0.1.0-py3-none-any.whl.
File metadata
- Download URL: jsonx_cli-0.1.0-py3-none-any.whl
- Upload date:
- Size: 10.6 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.2.0 CPython/3.12.12
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
ed9f00b3de29fbc6ba3f43ff880b09d5b0beaddcec64fdb99cefe71689a6762f
|
|
| MD5 |
064c7db29e7ab08be9820be433174f15
|
|
| BLAKE2b-256 |
2c87a8b5e14f2c8381623b3bd84fb171146e8e2858c80cdfbd903b090c75029c
|