Skip to content

Instantly share code, notes, and snippets.

@muresan
Created October 20, 2020 13:12
Show Gist options
  • Save muresan/643c631d6e88732cfd210c750765ac99 to your computer and use it in GitHub Desktop.
Save muresan/643c631d6e88732cfd210c750765ac99 to your computer and use it in GitHub Desktop.
json/yaml conversion as bash functions using python
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