Bash CLI Remove Quotes From Output Of A Command


Answer :

You can use the tr command to remove the quotes:

my_json=$(cat ~/Downloads/json.txt | jq '.name' | tr -d \") 

In the particular case of jq, you can specify that the output should be in raw format:

   --raw-output / -r:     With this option, if the filter´s result is a string then  it  will    be  written directly to standard output rather than being formatted    as a JSON string with quotes. This can be useful for making jq fil‐    ters talk to non-JSON-based systems. 

To illustrate using the sample json.txt file from your link:

$ jq '.name' json.txt "Google" 

whereas

$ jq -r '.name' json.txt Google 

Comments

Popular posts from this blog

Are Regular VACUUM ANALYZE Still Recommended Under 9.1?

Can Feynman Diagrams Be Used To Represent Any Perturbation Theory?