How to convert a json response into yaml in bash

后端 未结 6 1975
不知归路
不知归路 2020-12-31 11:04

I read data from a json file with jq. I wanna append the results into a yaml file, but I dont get it working. I am quite new to shell programming. My goal is to append that

6条回答
  •  予麋鹿
    予麋鹿 (楼主)
    2020-12-31 12:02

    Another oneliner:

    python -c 'import yaml, sys; print(yaml.dump(yaml.load(open(sys.argv[1])), default_flow_style=False))' input.json
    

    (exploiting the fact that valid json is also valid yaml)

    And yaml to json:

    python -c 'import yaml, json, sys; print(json.dumps(yaml.load(open(sys.argv[1])), indent=2))' input.yaml
    

提交回复
热议问题