给定这个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过滤并选择拥有MODE: D属性的features。据我所知,查询jq .[] | select(.MODE == "D")应该可以工作,但它不工作!
我遗漏了什么?
提前谢谢。
发布于 2014-11-04 17:56:44
jq ' .. | select( has("properties") )? | select( .properties.MODE == "D")'
问号告诉jq忽略错误。那个..。是递归到对象中
jq '.features[] | select(.properties.MODE == "D")'
将得到您所追求的结果,而不需要递归,只需注意方法中的差异。
发布于 2014-11-04 17:56:52
你错过了很多。您使用了.[],但这应该实现什么呢?MODE是特性的properties对象的属性。
.features | map(select(.properties.MODE == "D"))https://stackoverflow.com/questions/26741075
复制相似问题