Created
April 29, 2015 00:13
-
-
Save kevinschoon/024b9cc9fd05b6a95299 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/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