| Crates.io | xqpath |
| lib.rs | xqpath |
| version | 1.4.3 |
| created_at | 2025-07-27 06:07:00.431588+00 |
| updated_at | 2025-08-07 08:07:02.976555+00 |
| description | A high-performance jq-inspired path extractor and updater for structured data in Rust with advanced debugging, configuration management and interactive debugging capabilities |
| homepage | |
| repository | https://github.com/ThneS/xqpath |
| max_upload_size | |
| id | 1769749 |
| size | 768,353 |
高性能的 jq 风格结构化数据路径提取库 | 提供 Rust API 和命令行工具
[
](https://craXQPath v1.4.3 拥有完整的测试覆盖:
.field、[index]、*、** 等常用路径# 安装库
cargo add xqpath
# 安装命令行工具
cargo install xqpath
use xqpath::{query, query_one, exists};
use serde_json::json;
let data = r#"{
"users": [
{"name": "Alice", "age": 30},
{"name": "Bob", "age": 25}
]
}"#;
// 查询多个值
let names = query!(data, "users[*].name").unwrap();
// [String("Alice"), String("Bob")]
// 查询单个值
let first_name = query_one!(data, "users[0].name").unwrap();
// Some(String("Alice"))
// 检查路径是否存在
let has_users = exists!(data, "users").unwrap();
// true
# 基本查询
echo '{"users": [{"name": "Alice"}]}' | xqpath get 'users[*].name'
xqpath get '.config.version' -f config.yaml
# 路径检查和类型
xqpath exists '.user.email' -f data.json
xqpath type '.users' -f data.json
# 计数和键名
xqpath count '.users[*]' -f data.json
xqpath keys '.config' -f settings.json
# 格式转换
xqpath convert yaml -f config.json
xqpath validate -f data.json
# 配置管理 (v1.4.3+)
xqpath config show # 显示当前配置
xqpath config set debug.level trace # 设置配置项
xqpath config reset # 重置配置
# 交互式调试器 (v1.4.3+)
xqpath interactive-debug # 启动交互式调试器
xqpath interactive-debug -f data.json # 预加载数据文件
# 调试和性能分析
xqpath debug '.complex.path' -f data.json
xqpath trace '.users[*]' -f data.json --detailed
# 基础访问
.field # 字段访问
.nested.field # 嵌套字段
[0] # 数组索引
[*] # 数组通配符
.users[*].name # 组合使用
# 注意:高级操作如递归搜索(.config.**)和管道操作(.users | length)
# 计划在未来版本中实现
# 显示当前配置
xqpath config show
# 设置配置项
xqpath config set debug.level trace
xqpath config set performance.memory_limit 2GB
xqpath config set features.colored_output false
# 重置配置
xqpath config reset
debug.level (trace/debug/info/warn/error)performance.memory_limit, performance.timeout, performance.cache_sizefeatures.colored_output, features.auto_backup# 启动交互式调试器
xqpath interactive-debug
# 预加载数据文件
xqpath interactive-debug -f data.json
# 数据管理
:load <file> # 加载数据文件
:save <file> # 保存当前数据
# 查询和检查
:inspect <path> # 检查指定路径
:run <query> # 运行查询
.users[*].name # 直接运行查询
# 断点管理
:bp <path> # 设置断点
:bp-list # 列出断点
:bp-rm <id> # 删除断点
# 监视点管理
:watch <expression> # 设置监视点
:watch-list # 列出监视点
:watch-rm <id> # 删除监视点
# 调试信息
:vars # 列出变量
:stack # 显示调用栈
:reset # 重置会话
# 帮助和退出
:help # 显示帮助
:quit # 退出调试器
# 调试模式 - 显示详细执行信息
xqpath debug '.complex.query' -f data.json
# 输出: 解析时间、执行时间、查询路径、错误分析
# 执行跟踪 - 追踪查询执行过程
xqpath trace '.users[*].name' -f data.json --detailed
# 输出: 执行时间统计、结果类型分析
# 注意:profile、benchmark、monitor等高级性能分析功能
# 计划在未来版本中实现
// 优雅的错误处理
match query!(data, ".some.path") {
Ok(result) => println!("Found: {:?}", result),
Err(e) => eprintln!("Error: {}", e),
}
// 可选字段查询
let optional = query_one!(data, ".user.email")?; // 返回 Option<Value>
XQPath v1.4.3 拥有完整的测试覆盖:
# 克隆项目
git clone https://github.com/ThneS/xqpath.git
cd xqpath
# 快速测试核心功能
cargo test --lib
# 完整测试 (包括所有特性)
cargo test
# 快速测试核心功能
cargo test --lib # 58个单元测试
# 特定功能测试
cargo test --test config_debug_features # 配置管理 (9个测试)
cargo test --test enhanced_debugger # 交互式调试器 (5个测试)
cargo test --test integration # 集成测试 (11个测试)
cargo test --test advanced_functions # 高级函数 (11个测试)
# 完整测试
cargo test # 所有132个测试
# 原生cargo方式
cargo test --features config-management,interactive-debug
# 开发前检查
make dev-check # 格式化 + 检查 + 快速测试
# 代码质量
make fmt # 代码格式化
make lint # 代码检查
make check # 语法检查
# 构建
make build # 开发构建
make release # 发布构建
项目支持多种配置方式,配置文件位于 config/ 目录:
config/
├── examples/ # 配置示例
├── templates/ # 配置模板
└── profiles/ # 预定义配置
详细的开发指南请参考 docs/test-optimization.md。
项目已集成完整的 CI/CD 流程:
# 模拟CI快速检查流程
make dev-check
# 模拟CI完整测试流程
make ci-check
# 模拟发布前检查
make pre-release
欢迎贡献代码和反馈!查看 贡献指南 了解详情。
本项目采用 Apache-2.0 许可证。
XQPath - 让结构化数据处理变得简单高效 🚀