bash 如何删除jq输出中的双引号以解析bash中的json文件?

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/44656515/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-08 22:33:58  来源:igfitidea点击:

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

bashawksedjq

提问by Chris F

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:

我使用JQ解析一个JSON文件,如这里。但是,字符串值的结果按预期包含“双引号”,如下所示:

$ 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_commandcan I use?

some_other_command可以使用什么?

回答by Charles Duffy

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

使用-r(or --raw-output) 选项发出原始字符串作为输出:

jq -r '.name' <json.txt