rzl*_*vmp 12 linux command-line json yaml converters
如何在命令行中将 JSON 文件转换为 YAML,反之亦然?
欢迎任何方式。
pba*_*tey 34
更新:从yq版本 4.18开始:
标志-p可-o让您指定输入和输出格式。您可以在 yaml、json和xml 之间进行转换!
yq -p json -o yaml file.json # json -> yaml
yq -p json -o xml file.json # json -> xml
yq -p yaml -o json file.yaml # yaml -> json
yq -p yaml -o xml file.yaml # yaml -> xml
yq -p xml -o json file.xml # xml -> json
yq -p xml -o yaml file.xml # xml -> yaml
Run Code Online (Sandbox Code Playgroud)
对于yq版本 4.8.0:
yq e -P file.json产生 YAML
yq e -j file.yaml产生 JSON
e或eval单独评估每个文件。ea或者eval-all先合并它们。-P或--prettyPrint输出 YAML-j或--tojson输出 JSON