[
{
"firstname": "Alexander",
"lastname": "Smith",
"middlename": "Johnson",
"birthyear": 1918,
"deathyear": 1955,
"gender": "M",
"city": "Madison",
"state": "Wisconsin"
},
{
"firstname": "Lucy Jo Mary",
"lastname": "Carrie-Paulson",
"birthyear": 1967,
"deathyear": null,
"gender": "F",
"city": "Omaha",
"state": "Nebraska"
},
{
"firstname": "Jeremiah",
"lastname": "Springfield, Jr.",
"middlename": "Jebediah",
"birthyear": 1942,
"deathyear": 2003,
"gender": "M",
"city": "Kalamazoo",
"state": "Michigan"
}
]
如何获得名使用人的杰克从上面的json中,当没有中间名字存在于其中?
输出:露西·乔·玛丽
答案1
jq -r '.[]|select(.middlename|not).firstname'
这将为您提供没有middlename
属性或middlename
属性为 boolean 的条目的名字false
。
jq -r '.[]|select(has("middlename")|not).firstname'
将为您提供没有middlename
.