Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

remove double quotes from json string using sed

I am trying to remove double quotes from a string using this command but the sed always adds the quotes, not sure what’s wrong with this.

value = ["some_json_object"]

json string passing in as new_value:

"{\"new_name\":\"foo\",\"value\":\"bar\"}"

sed -i -e "s/some_json_object/jsondecode($new_value)/"

output:

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

["jsondecode({"new_name":"foo","value":"bar"})"]

expected_output:

[jsondecode({"new_name":"foo","value":"bar"})]

>Solution :

sed didn’t add the quotes, they’re in the original file and you don’t remove them. Include them in the pattern you’re replacing.

sed -i -e "s/\"some_json_object\"/jsondecode($new_value)/"
Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading