3

鉴于此 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")应该有效,但它没有!

我错过了什么?

提前致谢。

4

2 回答 2

2

jq ' .. | select( has("properties") )? | select( .properties.MODE == "D")'

问号告诉 jq 忽略错误。.. 是递归到对象

jq '.features[] | select(.properties.MODE == "D")'

无需递归即可获得您想要的结果,只是为了注意方法的差异

供参考:https ://github.com/stedolan/jq/issues/610

于 2014-11-04T17:56:44.623 回答
1

你错过了很多。你用过.[],但那应该完成什么?是特征对象的属性MODEproperties

.features | map(select(.properties.MODE == "D"))
于 2014-11-04T17:56:52.377 回答