
#!/bin/sh
# File	: json-string2lines2values.sh
# By	: Maarten.deBoer@Atos.net, 221110
# Subject	: Script to split JSON-string into VAR's with SINGLE values
JSON_STR='{"Content":"Value1","CreationMethod":"Value2","database":"Value3","DeviceType":"Value4"}'

#JSON_STR='{"ansible11":{"nao_quota_disk_limit":"11GB","nao_qtree_security_style":"unix"} , "ansible12":{"nao_quota_disk_limit":"12GB","nao_qtree_security_style":"ntfs"} , "ansible13":{"nao_quota_disk_limit":"13GB","nao_qtree_security_style":"mixed"} }'


echo ""
echo "${JSON_STR}"
echo ""
# Check if 1st char is { (JSON-string), remove { (at begin) and } (at end)
echo ${JSON_STR}|grep ^{|sed 's/^{//g'|sed 's/}$//g'
echo ""
# And make lines of it
echo ${JSON_STR}|grep ^{|sed 's/^{//g'|sed 's/}$//g'|tr ',' '\n'
echo ""


# From JSON_STR, remove {}, make rows, select VAR (before:), fill with VALUE (after :) and remove "
CONTENT=`echo ${JSON_STR}|grep ^{|sed 's/^{//g'|sed 's/}$//g'|tr ',' '\n'|grep -i Content|awk -F\: '{print $2}'|sed 's/"//g'`
CREATIONMETHOD=`echo ${JSON_STR}|grep ^{|sed 's/^{//g'|sed 's/}$//g'|tr ',' '\n'|grep -i creationmethod|awk -F\: '{print $2}'|sed 's/"//g'`
DATABASE=`echo ${JSON_STR}|grep ^{|sed 's/^{//g'|sed 's/}$//g'|tr ',' '\n'|grep -i DATABASE|awk -F\: '{print $2}'|sed 's/"//g'`
DEVICETYPE=`echo ${JSON_STR}|grep ^{|sed 's/^{//g'|sed 's/}$//g'|tr ',' '\n'|grep -i DEVICETYPE|awk -F\: '{print $2}'|sed 's/"//g'`

echo "CONTENT=${CONTENT}"
echo "CREATIONMETHOD=${CREATIONMETHOD}"
echo "DATABASE=${DATABASE}"
echo "DEVICETYPE=${DEVICETYPE}"

  
  

