Last active
April 20, 2020 06:46
-
-
Save lichti/5120de158ed6bef2880f to your computer and use it in GitHub Desktop.
Script to convert yml to json
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/bash | |
BYellow='\033[1;33m' | |
BGreen='\033[1;32m' | |
Color_Off='\033[0m' | |
LOCALPATH=$PWD | |
OUTPUT=$LOCALPATH/OUTPUT | |
if [ ! -d $OUTPUT ]; then | |
mkdir -p $OUTPUT | |
fi | |
if [ -z "$1" ]; then | |
for FILE in $LOCALPATH/*.yml | |
do | |
F_IN=`basename $FILE` | |
F_OUT=`basename $FILE .yml` | |
echo -e "Processing ${BYellow}${F_IN}${Color_Off} to ${BGreen}${F_OUT}.json${Color_Off}" | |
ruby -r json -r yaml -e "yaml = YAML.load(File.read('$FILE')); print yaml.to_json" > $OUTPUT/$F_OUT.json | |
done | |
else | |
if [ -f $1 ];then | |
F_IN=`basename $1` | |
F_OUT=`basename $1 .yml` | |
echo -e "Processing ${BYellow}${F_IN}${Color_Off} to ${BGreen}${F_OUT}.json${Color_Off}" | |
ruby -r json -r yaml -e "yaml = YAML.load(File.read('$1')); print yaml.to_json" > $OUTPUT/$F_OUT.json | |
else | |
echo "File not found" | |
fi | |
fi |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment