Skip to content

Instantly share code, notes, and snippets.

@lorin
Created November 16, 2012 02:36
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save lorin/4083433 to your computer and use it in GitHub Desktop.
Save lorin/4083433 to your computer and use it in GitHub Desktop.
Convert from json to yaml
#!/usr/bin/env python
""" Convert json to YAML
Usage: json2yaml.py [infile]
"""
import args
import json
import sys
import yaml
def main(fin=sys.stdin, fout=sys.stdout):
data = json.load(fin)
yaml.safe_dump(data, stream=fout, default_flow_style=False, indent=4)
if __name__ == '__main__':
if args.files:
fname, = args.files
fin = open(fname)
else:
fin = sys.stdin
main(fin)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment