Reputation: 483
i have a following string:
{"name":"ram","details":[{'subjects':{'service_location':'c:/A.exe','url':'http://A.zip'}}]}
In the above string few strings have single quotes around them. so, how can i replace single quotes with double quotes in the above string and get as follows:
{"name":"ram","details":[{"subjects":{"service_location":"c:/A.exe","url":"http://A.zip"}}]}
Upvotes: 3
Views: 10383
Reputation: 208052
With tr
to translate individual characters:
your_command | tr "'" '"'
Or, if that is too much typing:
your_command | tr \' \"
:-)
Upvotes: 1
Reputation: 1630
Extending @RavinderSingh13 answer, use following command to convert your string.
echo '{"name":"ram","details":'"[{'subjects':{'service_location':'c:/A.exe','url':'http://A.zip'}}]}" | sed "s/'/\"/g"
Upvotes: 3
Reputation: 133770
@Learner: Try a sed
solution:
sed "s/'/\"/g" Input_file
OR
your_command | sed "s/'/\"/g"
Upvotes: 8
Reputation: 18411
Following will convert all the single quotes to double quotes. This used awk
's inbuilt gsub
function to search and replace the text. Here, we are telling awk to replace s
which is equal to single quotes. Once single quote is found replace it with double quote. 1 is to print the line.
awk -v s="'" '{gsub(s,"\"")}1' file
OR
source-of-json | awk -v s="'" '{gsub(s,"\"")}1'
Upvotes: 0