serialize json

master
ademant 2020-10-04 12:51:43 +02:00
parent 1ce158ea0d
commit 1eaf25f777
1 changed files with 3 additions and 0 deletions

3
serialize_json.sh Executable file
View File

@ -0,0 +1,3 @@
#!/bin/bash
read injson
echo ${injson}|sed -e 's/"//g;s/,/\n/g;s/{/{\n/g;s/}/\n}/g'|awk -F ":" 'BEGIN{topic=""};/:{/{length(topic)>0 ? topic=topic$1"/" : topic=$1"/"};!/{/&&!/}/{print "\""topic$1"\":\""$2"\""};/}/{l=split(topic,t,"/");topic="";for(i=1;i<(l-1);i++)topic=topic""t[i]"/"}'