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

Popular posts from this blog

commonjs - How to write a typescript definition file for a node module that exports a function? -

openid - Okta: Failed to get authorization code through API call -

thorough guide for profiling racket code -