Created
October 20, 2020 13:12
-
-
Save muresan/643c631d6e88732cfd210c750765ac99 to your computer and use it in GitHub Desktop.
json/yaml conversion as bash functions using python
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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())))' | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment