Convert JSON to YAML. Parsing JSON to YAML

前端 未结 6 860
南笙
南笙 2020-12-16 01:18

I\'m working with configuration files so I need to convert JSON to YAML. For example I have this JSON file:

{
  "foo": "bar",
  "baz&         


        
6条回答
  •  感动是毒
    2020-12-16 01:34

    function yaml_validate {
      python -c 'import sys, yaml, json; yaml.safe_load(sys.stdin.read())'
    }
    
    function yaml2json {
      python -c 'import sys, yaml, json; print(json.dumps(yaml.safe_load(sys.stdin.read())))'
    }
    
    function yaml2json_pretty {
      python -c 'import sys, yaml, json; print(json.dumps(yaml.safe_load(sys.stdin.read()), indent=2, sort_keys=False))'
    }
    
    function json_validate {
      python -c 'import sys, yaml, json; json.loads(sys.stdin.read())'
    }
    
    function json2yaml {
      python -c 'import sys, yaml, json; print(yaml.dump(json.loads(sys.stdin.read())))'
    }
    

    More Bash tricks at http://github.com/frgomes/bash-scripts

提交回复
热议问题