bin/yaml2json

21 lines
522 B
Plaintext
Raw Normal View History

2024-07-09 00:29:15 -05:00
#!/usr/bin/env python3
#
2024-02-03 10:35:36 -06:00
# YAML to JSON conversion script
# Based on https://www.geeksforgeeks.org/convert-yaml-to-json/
#
2024-07-09 00:29:15 -05:00
# This script takes a YAML file as the first arg, converts the
# YAML content to JSON, and outputs the converted JSON content
# to stdout.
2024-02-03 10:35:36 -06:00
2024-07-09 00:29:15 -05:00
import json
import sys
2024-02-03 10:35:36 -06:00
2024-07-09 00:29:15 -05:00
import yaml
2024-02-03 10:35:36 -06:00
2024-07-09 00:29:15 -05:00
try:
print(json.dumps(yaml.load(open(sys.argv[1]), Loader=yaml.FullLoader), indent=4))
except IndexError:
print("YAML file must be supplied as first arg")
except FileNotFoundError:
print("YAML file not found")