jrv-yaml-toolkit
Everything you need to work with YAML files: validate syntax, format/prettify, convert to/from JSON, query with dot-path expressions, merge multiple files, and check against a schema.
Quick Start
CODEBLOCK0
Commands
| Command | Description |
|---|
| INLINECODE0 | Check YAML syntax, report errors with line numbers |
| INLINECODE1 |
Pretty-print YAML with consistent indentation |
|
to-json <file> | Convert YAML to JSON |
|
from-json <file> | Convert JSON to YAML |
|
get <file> <path> | Get value at dot-path (e.g.
server.host) |
|
set <file> <path> <val> | Set value at dot-path, output updated YAML |
|
merge <file1> <file2> ... | Deep-merge YAML files (right overrides left) |
|
lint <file> --schema <s> | Validate keys against a schema YAML |
|
keys <file> | List all keys as flattened dot-paths |
|
minify <file> | Output compact single-line YAML |
Options
| Flag | Description |
|---|
| INLINECODE11 | Write output to file instead of stdout |
| INLINECODE12 |
Indentation spaces (default: 2) |
|
--allow-unicode | Allow unicode in output (default: true) |
Use Cases
- - DevOps: Validate Kubernetes and Docker Compose configs before applying
- CI/CD: Merge environment-specific YAML overrides
- Config management: Query and patch config values programmatically
- Data pipelines: Convert between JSON and YAML for different tools
- Documentation: List all config keys for auto-generated docs
Exit Codes
- -
0 — Success - INLINECODE15 — Validation error or key not found
- INLINECODE16 — File not found or parse error
jrv-yaml-toolkit
处理YAML文件所需的一切:验证语法、格式化/美化、与JSON互转、通过点路径表达式查询、合并多个文件以及根据模式检查。
快速开始
bash
验证YAML语法
python3 scripts/yaml_toolkit.py validate config.yaml
格式化/美化YAML
python3 scripts/yaml_toolkit.py format messy.yaml
将YAML转换为JSON
python3 scripts/yaml_toolkit.py to-json config.yaml
将JSON转换为YAML
python3 scripts/yaml_toolkit.py from-json data.json
通过点路径查询值
python3 scripts/yaml_toolkit.py get config.yaml server.host
设置值
python3 scripts/yaml_toolkit.py set config.yaml server.port 8080
合并多个YAML文件(后面的文件覆盖前面的)
python3 scripts/yaml_toolkit.py merge base.yaml override.yaml
根据简单模式文件进行检查
python3 scripts/yaml_toolkit.py lint config.yaml --schema schema.yaml
列出所有键(扁平化点路径)
python3 scripts/yaml_toolkit.py keys config.yaml
压缩YAML(单行流式风格)
python3 scripts/yaml_toolkit.py minify config.yaml
命令
| 命令 | 描述 |
|---|
| validate <文件> | 检查YAML语法,报告错误并显示行号 |
| format <文件> |
以一致的缩进美化打印YAML |
| to-json <文件> | 将YAML转换为JSON |
| from-json <文件> | 将JSON转换为YAML |
| get <文件> <路径> | 获取点路径处的值(例如 server.host) |
| set <文件> <路径> <值> | 设置点路径处的值,输出更新后的YAML |
| merge <文件1> <文件2> ... | 深度合并YAML文件(右侧覆盖左侧) |
| lint <文件> --schema <模式> | 根据模式YAML验证键 |
| keys <文件> | 将所有键列出为扁平化点路径 |
| minify <文件> | 输出紧凑的单行YAML |
选项
| 标志 | 描述 |
|---|
| --output <文件> | 将输出写入文件而非标准输出 |
| --indent N |
缩进空格数(默认:2) |
| --allow-unicode | 允许输出中包含Unicode(默认:true) |
使用场景
- - DevOps:在应用前验证Kubernetes和Docker Compose配置
- CI/CD:合并特定环境的YAML覆盖配置
- 配置管理:以编程方式查询和修补配置值
- 数据管道:在不同工具间转换JSON和YAML
- 文档:列出所有配置键以生成自动文档
退出代码
- - 0 — 成功
- 1 — 验证错误或未找到键
- 2 — 未找到文件或解析错误