mirror of
https://codeberg.org/hyperreal/admin-scripts
synced 2025-01-18 15:53:45 +01:00
Add yaml2json
This commit is contained in:
parent
2ae4630a6b
commit
3201b9da57
24
python/yaml2json
Executable file
24
python/yaml2json
Executable file
@ -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")
|
Loading…
Reference in New Issue
Block a user