Created
September 19, 2012 22:18
-
-
Save danwaz/3752702 to your computer and use it in GitHub Desktop.
Convert JSON to YAML
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 | |
# Converts a directory of JSON files into YAML files! Cool! | |
# Requires json2yaml node package https://npmjs.org/package/json2yaml | |
# receive the directory or treat current directory as the base directory | |
DIR=$1 | |
if [ -d $DIR ]; then | |
cd $DIR; | |
echo $PWD; | |
# Loop through the directory looking for .JSON extensions | |
for f in *.json | |
do | |
FILE_NAME=`echo "$f" | grep -oP '.*(?=\.json$)'` | |
# only run this when we're sure there is no yml file for the $FILE_NAME | |
if [ ! -e "$FILE_NAME.yml" ]; then | |
# do the conversion | |
echo "Creating $FILE_NAME.yml" | |
json2yaml $f > "$FILE_NAME.yml" | |
else | |
echo "The yaml file for $f is already there, bro." | |
fi | |
done | |
# exit cleanly | |
exit 0 | |
else | |
echo "No Such Directory, dood." | |
exit 1 | |
fi |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment