使用jq将JSON转换为纯文本

使用jq将JSON转换为纯文本,json,jq,Json,Jq,假设我得到了以下json响应: { "author": "tomek", "title": "helloworld", "test": "sampletextonetwothree" } 可以这样显示吗:使用jq author=tomek title=helloworld test=sampletextonetwothree 也许有更好的方法,但这是可行的: c

假设我得到了以下json响应:

{
  "author": "tomek",
  "title": "helloworld",
  "test": "sampletextonetwothree"
}
可以这样显示吗:使用jq

author=tomek
title=helloworld
test=sampletextonetwothree

也许有更好的方法,但这是可行的:

cat response.json | jq -r 'to_entries| map([.key, .value]) | map([join("=")]) | flatten | .[]'


也许有更好的方法,但这是可行的:

cat response.json | jq -r 'to_entries| map([.key, .value]) | map([join("=")]) | flatten | .[]'

jq'to_entries[]\\.key=\.value' 应该这样做

jq'to_entries[]\\.key=\.value'
应该这样做

连接值的另一种方法是使用:


连接值的另一种方法是使用:


这回答了你的问题吗?查看链接的答案jq-r'to_entries[]|\.key=\\\.value\'input.jsonYes,这是完美的回答您的问题吗?请参阅链接的答案jq-r'to_entries[]\\.key=\\.value\'input.jsonYes,这很完美您缺少一个结束单引号Ethanks@philippe您缺少一个结束单引号Ethanks@PhilippeNice!不知怎的,我试着这么做,结果却出错了。我一定是在什么地方漏掉了一个括号转义。事实上,我刚刚注意到你希望它不带引号,所以你可能更喜欢@Philippe's answer。你可以通过添加-r标志来删除引号。谢谢大家!工作起来很有魅力!美好的不知怎的,我试着这么做,结果却出错了。我一定是在什么地方漏掉了一个括号转义。事实上,我刚刚注意到你希望它不带引号,所以你可能更喜欢@Philippe's answer。你可以通过添加-r标志来删除引号。谢谢大家!工作起来很有魅力!
jq -r 'to_entries[] | .key + "=" + .value'