鉴于此JSON
{
"type": "FeatureCollection",
"features": [
{
"type": "Feature",
"properties": {
"MODE": "A"
},
"geometry": {
"type": "Point",
"coordinates": [
-69.23583984375,
45.460130637921004
]
}
},
{
"type": "Feature",
"properties": {
"MODE": "D"
},
"geometry": {
"type": "Point",
"coordinates": [
-69.23651039600372,
45.46053888199693
]
}
}
]
}
我想使用jq过滤并选择拥有features
属性的MODE: D
。据我所知,查询jq .[] | select(.MODE == "D")
应该有效,但它没有!
我错过了什么?
提前致谢。
答案 0 :(得分:2)
jq ' .. | select( has("properties") )? | select( .properties.MODE == "D")'
问号告诉jq忽略错误。 ..是递归到对象
jq '.features[] | select(.properties.MODE == "D")'
只是为了注意方法中的差异
,可以得到你没有递归的结果答案 1 :(得分:1)
你错过了很多。您使用了.[]
但是应该完成什么? MODE
是要素的properties
对象的属性。
.features | map(select(.properties.MODE == "D"))