From 3201b9da5729fee582f0bf3be639894e719e7784 Mon Sep 17 00:00:00 2001 From: Jeffrey Serio Date: Thu, 19 Dec 2024 18:58:27 -0600 Subject: [PATCH] Add yaml2json --- python/yaml2json | 24 ++++++++++++++++++++++++ 1 file changed, 24 insertions(+) create mode 100755 python/yaml2json diff --git a/python/yaml2json b/python/yaml2json new file mode 100755 index 0000000..f7a582b --- /dev/null +++ b/python/yaml2json @@ -0,0 +1,24 @@ +# /// script +# dependencies = [ +# "yaml", +# ] +# /// + +# YAML to JSON conversion script +# Based on https://www.geeksforgeeks.org/convert-yaml-to-json/ +# +# This script takes a YAML file as the first arg, converts the +# YAML content to JSON, and outputs the converted JSON content +# to stdout. + +import json +import sys + +import yaml + +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")