我必须使用JQ过滤具有最接近对象名称的JSON文件。
我已经尝试使用命令:
jq '.data[] |select(.orderid=="40007600")' output.json
,但是该命令仅过滤名称正确的对象。我想过滤以字符串“ 40007”开头的对象,例如:.orderid="40007"
。
{
"data": [
{
"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"
},
{
"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"
},
{
"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"
}
]
}
答案 0 :(得分:1)
jq '.data[] | select(.orderid | startswith("40007"))' output.json