Navigation Menu

Skip to content

Instantly share code, notes, and snippets.

@sbp
Created May 22, 2011 21:00
Show Gist options
  • Star 5 You must be signed in to star a gist
  • Fork 4 You must be signed in to fork a gist
  • Save sbp/985889 to your computer and use it in GitHub Desktop.
Save sbp/985889 to your computer and use it in GitHub Desktop.
Convert JSON to YAML
#!/bin/sh
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)
' $@
@azizzoaib786
Copy link

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

@ausarb
Copy link

ausarb commented Nov 15, 2018

That syntax error is a Python 3 thing, where print is now a function. https://docs.python.org/3.0/whatsnew/3.0.html#print-is-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