Skip to content

Instantly share code, notes, and snippets.

@m2mIO-gister
Created March 22, 2012 00:20
Show Gist options
  • Save m2mIO-gister/2154368 to your computer and use it in GitHub Desktop.
Save m2mIO-gister/2154368 to your computer and use it in GitHub Desktop.
Public
#!/bin/bash
# Find a value in simple JSON object from a key
# $1: key to find
# $2: JSON
find() {
for i in $(echo $2 | tr "," "\n"); do
i=`echo $i | sed "s/{//g" | sed "s/}//g" | sed "s/\"//g"`
set=($(echo $i | tr ":" "\n"))
if [ "$1" == "${set[0]}" ]; then
echo ${set[1]}
fi
done
}
# Set BASH variables from a simple JSON object
# $1: json_passed_to_script
set_as_variables() {
echo -e "$1" >> /home/ubuntu/json_passed_to_script
for i in $(echo $1 | tr "," "\n"); do
i=`echo $i | sed "s/{//g" | sed "s/}//g" | sed "s/\"//g"`
set=($(echo $i | tr ":" "\n"))
echo "${set[0]}=${set[1]}"
export ${set[0]}="${set[1]}"
echo -e "${set[1]}" >> /home/ubuntu/${set[0]}
done
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment