You need to enable JavaScript to run this app. 如何使用jq基于内容删除GeoJSON数组中符合指定条件的元素
优惠活动
大模型
产品
解决方案
定价
更多

如何使用jq基于内容删除GeoJSON数组中符合指定条件的元素

你可以直接使用以下jq命令实现需求:

jq 'del(.features[] | select(.properties.algorithm == "parameterA"))' your-file.json

命令逻辑说明

  • .features[] 遍历GeoJSON中features数组的所有元素
  • select(.properties.algorithm == "parameterA") 筛选出properties字段下algorithm值为parameterA的元素
  • del() 对筛选出的元素执行删除操作,其余字段(包括外层的type、顶层properties等)都会保持原样不变

落地使用方式

  1. 如果你需要生成新的结果文件,直接用重定向即可:
jq 'del(.features[] | select(.properties.algorithm == "parameterA"))' 原文件.json > 新文件.json
  1. 如果你需要直接修改原文件,给jq加上-i参数即可(注意macOS自带的低版本jq不支持该参数,可通过brew安装新版jq,或者用上面的重定向方式替代):
jq -i 'del(.features[] | select(.properties.algorithm == "parameterA"))' 你的文件.json

内容的提问来源于stack exchange,提问作者raylight

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.10.09 22:57:03