I'm generating a JSON file with a shell script but I can't find a solution to automatically get rid of the last comma just before the ending }. Here is my code:echo { >> out_filefor i in 3 4 5 6 7 #ends at 298doy=$isommeMag=`awk -F '=' '/'$y'/{sommeMag+=$2}END{print sommeMag}'` /myfolder/... store=mag$yif [ -z $sommeMag ] #checks is variable is empty    then        echo  \ $store\:0,>> out_file    else        echo \$store\:$sommeMag, >> out_file    fidoneecho } >> out_fileThe file is ending this way :{ mag297:0, mag298:0, <-- syntaxt error}The file should end this way :{... mag297:0, mag298:0 <-- no more comma}How can I manage that?The code has been edited to be more readable here.
JSON correct construction
shell script;json