Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to remove double-quotes in jq output for parsing json files in bash?

Tags:

bash

sed

awk

jq

I'm using jq to parse a JSON file as shown here. However, the results for string values contain the "double-quotes" as expected, as shown below:

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

How can I pipe this into another command to remove the ""? so I get

$ cat json.txt | jq '.name' | some_other_command Google 

What some_other_command can I use?

like image 292
Chris F Avatar asked Jun 20 '17 14:06

Chris F


People also ask

How do you remove double quotes in jq?

If you want to strip the quotes, just pipe the output from this command to tr -d '"' .

Does JSON always use double quotes?

JSON names require double quotes.

What does jq do in bash?

jq command is used not only for reading JSON data but also to display data by removing the particular key. The following command will print all key values of Students. json file by excluding batch key. map and del function are used in jq command to do the task.


1 Answers

Use the -r (or --raw-output) option to emit raw strings as output:

jq -r '.name' <json.txt 
like image 196
3 revs, 2 users 83% Avatar answered Sep 20 '22 14:09

3 revs, 2 users 83%