-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathjsonToYaml.py
executable file
·34 lines (28 loc) · 969 Bytes
/
jsonToYaml.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
#!/Users/tfeiler/.virtualenvs/tjf_python_shellscripts/bin/python
import json, os, sys, yaml
def usage():
print(f"Usage: jsonToYaml.py <path_to_json>")
sys.exit(1)
if __name__ == "__main__":
if len(sys.argv) != 2:
usage()
"""
combo = ""
for line in sys.stdin:
combo += line
converted = yaml.dump(combo, default_flow_style=False)
print(converted)
"""
else:
json_file = sys.argv[1]
if not json_file.endswith(".json"):
usage()
else:
if os.path.isfile(json_file):
# thx https://stackoverflow.com/questions/50846431/converting-a-yaml-file-to-json-object-in-python
with open(json_file, 'r') as json_in:
loaded = json.load(json_in)
converted = yaml.dump(loaded, default_flow_style=False)
print(converted)
else:
usage()