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:
["jsondecode({"new_name":"foo","value":"bar"})"]
expected_output:
[jsondecode({"new_name":"foo","value":"bar"})]
CodePudding user response:
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)/"