mirror of
https://codeberg.org/hyperreal/bin
synced 2024-11-01 16:43:08 +01:00
21 lines
522 B
Python
Executable File
21 lines
522 B
Python
Executable File
#!/usr/bin/env python3
|
|
#
|
|
# 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")
|