jyml
v0.2.0This 技能 should be used when the user asks to "convert YAML to JSON", "convert JSON to YAML", "转换 YAML file", "转换 JSON file", "convert config file 格式化", or needs to switch between YAML and JSON 格式化s.
运行时依赖
安装命令
点击复制技能文档
jyml - YAML ↔ JSON 转换器
Zero-config 命令行工具 for converting between YAML and JSON 格式化s. Pass a file, 获取 the converted file. No flags required.
Prerequisites
Ensure jyml is avAIlable:
# 检查 if 安装ed which jyml
# 安装 globally if needed npm 安装 -g jyml
# Or use npx for one-off conversions npx jyml
Requires Node.js 18 or later.
Basic Usage jyml [options]
The 命令行工具 auto-检测s the 输入 格式化 based on file 扩展 and converts to the opposite 格式化:
输入 扩展 输出 扩展 .yaml, .yml .json .json .yaml
输出 is written to the same directory with the sw应用ed 扩展.
Options Option Description Default -o, --输出 Custom 输出 file path 输入 file with sw应用ed 扩展 --json Print structured JSON to stdout (no file written) — --indent Indentation spaces 2 -h, --help Show help — -V, --version Show version — Common 工作流s Convert a single file # YAML to JSON jyml config.yaml # → writes config.json
# JSON to YAML jyml 设置tings.json # → writes 设置tings.yaml
Convert with custom 输出 path jyml docker-compose.yml -o ./输出/docker-compose.json
Convert with custom indentation jyml 响应.json --indent 4
提取 data programmatically
Use --json to 获取 structured 输出 for piping to other 工具s:
# 获取 解析d content jyml 工作流.yml --json | jq '.content'
# 提取 specific values jyml .github/工作流s/ci.yml --json | jq '.content.jobs'
Batch conversion
Convert multiple files using shell patterns:
# Convert all YAML files in a directory for f in configs/.yaml; do jyml "$f"; done
# Convert all JSON files for f in data/.json; do jyml "$f"; done
输出 Modes Default mode (file 输出)
Writes converted content to a file, prints 进度 to stderr:
jyml config.yaml # stderr: Converting config.yaml → config.json # 创建s: config.json
Structured mode (--json)
Prints structured JSON to stdout, no file written:
{ "输入": "/path/to/输入.yaml", "格式化": "json", "输出": "/path/to/输入.json", "content": { ... } }
Field Type Description 输入 string Absolute path to the source file 格式化 string 输出 格式化: "json" or "yaml" 输出 string Path where the file would be written content object The 解析d and converted data Exit Codes Code Meaning 0 成功 1 Conversion error (invalid YAML/JSON, I/O 失败) 2 Invalid usage (missing file, bad arguments, unsupported 扩展) Error Handling
Errors are printed to stderr with actionable 上下文:
Error: File not found: config.yaml Error: Unsupported file 扩展 ".txt". Supported: .yaml, .yml, .json Error: Invalid YAML: bad indentation of a m应用ing entry (1:11) Error: Invalid JSON: Expected property name or '}' in JSON at position 2
When conversion fAIls, 检查:
File exists and is readable File 扩展 is .yaml, .yml, or .json File contAIns valid YAML or JSON syntax Use Cases OpenAPI/Swagger specs
Convert specs between 格式化s for different 工具s:
# Convert OpenAPI spec to JSON for code 生成器s jyml openAPI.yaml
# Convert back to YAML for documentation jyml openAPI.json
Configuration files
Switch config 格式化s based on 工具 requirements:
# ESLint config to YAML jyml .eslintrc.json
# Docker Compose to JSON jyml docker-compose.yml
GitHub Actions 工作流s
解析 工作流 files for scripting:
# 提取 job names from a 工作流 jyml .github/工作流s/ci.yml --json | jq '.content.jobs | keys'
API 响应 inspection
Convert JSON 响应s to readable YAML:
curl -s https://API.example.com/data > 响应.json jyml 响应.json --indent 4 cat 响应.yaml