shell - How to create a json array string from a string of comma separated values? -
i have string of comma separated values.
e.g. - "paris,mumbai,london,tokyo,boston"
now need string this:
"["paris","mumbai","london","tokyo","boston"]"
i able create array of strings using ifs. not able create above mentioned json array string need. please help.
"["paris","mumbai","london","tokyo","boston"]"
not formed json.
this correct format.
["paris","mumbai","london","tokyo","boston"]
it ugly... know:
echo "paris,mumbai,london,tokyo,boston" | perl -p -e "s/,/\",\"/g" | sed 's/^/[\"/g' | sed 's/$/\"]/g'
this returns:
["paris","mumbai","london","tokyo","boston"]
Comments
Post a Comment