格式化数组/对象时的jQuery Tsv错误 [英] Jq tsv error in formatting an array/object
本文介绍了格式化数组/对象时的jQuery Tsv错误的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我有一个json文件,我可以使用以下命令循环并获取所需的值.我试图在将这些值显示为表格格式时获得一些见识.我正在使用 @tsv
,但遇到错误 object({"release"; ...),不能使用tsv格式,只能是数组
.如何获得以下输出显示?
I have json file that I am able to loop and get the desired values with the below command. I am trying to gain some insights in displaying these values into a table format. I am using @tsv
but getting an error object ({"release":...) cannot be tsv-formatted, only array
. How can I get the below output display?
我想要的输出如下所示:
My desired output is shown below:
Release Installed Latest Old Deprecated
------- --------- ------ --- ----------
test-app 1.0.0 2.0.0 true false
jq:
cat test.json | jq '.test[] | select((.outdated or .deprecated) and ((.release|startswith("update")) | not) and ((.release|startswith("upgrade")) | not))'
json:
{
"test": [{
"release": "myapp1",
"Installed": {
"version": "0.3.0",
"appVersion": "v1.2.6"
},
"Latest": {
"version": "",
"appVersion": ""
},
"outdated": false,
"deprecated": false
}, {
"release": "myapp2",
"Installed": {
"version": "6.5.13",
"appVersion": "1.9.1"
},
"Latest": {
"version": "",
"appVersion": ""
},
"outdated": false,
"deprecated": false
}, {
"release": "test-app",
"Installed": {
"version": "1.0.0",
"appVersion": ""
},
"Latest": {
"version": "2.0.0",
"appVersion": ""
},
"outdated": true,
"deprecated": false
}, {
"release": "update-app",
"Installed": {
"version": "1.0.0",
"appVersion": ""
},
"Latest": {
"version": "3.0.0",
"appVersion": ""
},
"outdated": true,
"deprecated": false
}, {
"release": "upgrade-app",
"Installed": {
"version": "2.0.0",
"appVersion": ""
},
"Latest": {
"version": "2.0.0",
"appVersion": ""
},
"outdated": false,
"deprecated": true
}]
}
推荐答案
@csv
和 @tsv
都希望将数组作为输入,因此您可以追加以下内容到您的jq过滤器:
Both @csv
and @tsv
expect an array as input, so you could just append the following to your jq filter:
| [.release, .Installed.version, .Latest.version, .outdated, .deprecated]
| @tsv
这篇关于格式化数组/对象时的jQuery Tsv错误的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文