我有以下.json文字:
{
"error": 0,
"data": {
"0": {
"orderid": "40007600",
"price": "9.99",
"listingname": "iPhone 8",
"smallphoto": "https://images-eu.ssl-images-amazon.com/images/I/51b5iaLTjgL._SL160_.jpg",
"photo": "https://images-eu.ssl-images-amazon.com/images/I/51b5iaLTjgL.jpg"
},
"1": {
"orderid": "40007598",
"price": "9.99",
"listingname": "iPhone 8 Plus",
"smallphoto": "https://images-eu.ssl-images-amazon.com/images/I/51CVLqsSNkL._SL160_.jpg",
"photo": "https://images-eu.ssl-images-amazon.com/images/I/51CVLqsSNkL.jpg"
},
"4": {
"orderid": "40007595",
"price": "9.39",
"listingname": "Nadelflaschen",
"smallphoto": "https://images-eu.ssl-images-amazon.com/images/I/41OHDP2rAeL._SL160_.jpg",
"photo": "https://images-eu.ssl-images-amazon.com/images/I/41OHDP2rAeL.jpg"
},
}
我想要一个输出的jq脚本:
"9.99" "iPhone 8"
"9.99" "iPhone 8 Plus"
"9.39" "Nadelflaschen"
在.txt文件中。
来自“price”和“listingname”的.data []。
我试过
jq'.data [] | .price''。data [] | .listingname'
jq -M'.. | .price?// empty'&& '.. | .listingname //空“
两者都不起作用。你有什么想法吗?
答案 0 :(得分:0)
最接近的是:
jq '.data[] | .price, .listingname' data.json
返回:
"9.99"
"iPhone 8"
"9.99"
"iPhone 8 Plus"
"9.39"
"Nadelflaschen"
逗号:如果两个过滤器用逗号分隔,则输入相同 将被送入两个和两个过滤器的输出值流将 按顺序连接:首先,由...产生的所有输出 左表达式,然后是右边生成的所有输出。 例如,过滤器.foo,.bar,产生“foo”字段和 “bar”字段作为单独的输出。