mirror of
https://codeberg.org/hyperreal/bin
synced 2024-11-01 16:43:08 +01:00
Add yaml2json
This commit is contained in:
parent
909594bbd0
commit
4a36ddbb19
17
yaml2json
Executable file
17
yaml2json
Executable file
@ -0,0 +1,17 @@
|
|||||||
|
#!/usr/bin/env bash
|
||||||
|
|
||||||
|
# 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 and outputs the
|
||||||
|
# converted JSON to stdout.
|
||||||
|
|
||||||
|
set -e
|
||||||
|
|
||||||
|
if ! python -c "import yaml" &>/dev/null; then
|
||||||
|
echo -e "PyYAML is not installed."
|
||||||
|
fi
|
||||||
|
|
||||||
|
if ! python -c "import yaml, json; print(json.dumps(yaml.load(open('${1}'), Loader=yaml.FullLoader), indent=4))"; then
|
||||||
|
echo "Some kinda error occurred while attempting to convert YAML to JSON"
|
||||||
|
fi
|
Loading…
Reference in New Issue
Block a user