Skip to content

Instantly share code, notes, and snippets.

@ashafer01
Last active October 1, 2023 15:36
Show Gist options
  • Save ashafer01/ef551ce43eba10de467bd293ea4d5941 to your computer and use it in GitHub Desktop.
Save ashafer01/ef551ce43eba10de467bd293ea4d5941 to your computer and use it in GitHub Desktop.
python single-expression shell aliases to convert between yaml and json. accepts optional filename argument, defaults to stdin
macbook:~ % which yaml-to-json
yaml-to-json: aliased to python3 -c 'print(__import__("json").dumps(__import__("yaml").safe_load(open([*__import__("sys").argv[1:],"/dev/stdin"][0]).read()),indent=" "))'
macbook:~ % which json-to-yaml
json-to-yaml: aliased to python3 -c 'print(__import__("yaml").dump(__import__("json").load(open([*__import__("sys").argv[1:],"/dev/stdin"][0]))),end="")'
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment