bin/yaml2json

21 lines
522 B
Plaintext
Raw Normal View History

2024-07-09 07:29:15 +02:00
#!/usr/bin/env python3
#
2024-02-03 17:35:36 +01:00
# YAML to JSON conversion script
# Based on https://www.geeksforgeeks.org/convert-yaml-to-json/
#
2024-07-09 07:29:15 +02: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 17:35:36 +01:00
2024-07-09 07:29:15 +02:00
import json
import sys
2024-02-03 17:35:36 +01:00
2024-07-09 07:29:15 +02:00
import yaml
2024-02-03 17:35:36 +01:00
2024-07-09 07:29:15 +02: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")