Skip to content

Instantly share code, notes, and snippets.

@kevinschoon
Created April 29, 2015 00:13
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 kevinschoon/024b9cc9fd05b6a95299 to your computer and use it in GitHub Desktop.
Save kevinschoon/024b9cc9fd05b6a95299 to your computer and use it in GitHub Desktop.
#!/usr/bin/env python
"""
Convert YAML to JSON and JSON to YAML
"""
import yaml
import json
import sys
if __name__ == '__main__':
file_path = sys.argv[1]
with open(file_path, 'r') as fp:
raw = yaml.load(fp.read())
if file_path.split('.')[-1] == 'json':
sys.stdout.write(yaml.dump(raw))
if file_path.split('.')[-1] == 'yaml':
sys.stdout.write(json.dumps(raw))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment