Skip to content

Instantly share code, notes, and snippets.

What would you like to do?
Convert JSON to YAML
export PYTHONPATH=$HOME/usr/opt/pyyaml/lib/python2.6/site-packages
python -c '
import sys, json, yaml
with open(sys.argv[1]) as f:
print yaml.safe_dump(json.load(f), default_flow_style=False)
' $@
Copy link

azizzoaib786 commented Sep 4, 2018

print yaml.safe_dump(json.loads(f), default_flow_style=False)
SyntaxError: invalid syntax

Copy link

ausarb commented Nov 15, 2018

That syntax error is a Python 3 thing, where print is now a function.

print(yaml.safe_dump(json.load(f), default_flow_style=False))

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment