You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

JSONPath新手求助:获取指定机构名称的对象表达式

JSONPath查询:匹配指定机构名称的对象

原始JSON数据

{
  "total_institutions": 2,
  "count_by_institution": [
    {
      "institution": {
        "id": "03629",
        "name": "institutiona03629"
      },
      "total_branches": 5
    },
    {
      "institution": {
        "id": "03659",
        "name": "institutiona03659"
      },
      "total_branches": 3
    }
  ]
}

查询需求

作为JSONPath新手,需要编写一个JSONPath表达式,获取name等于institutiona03659的机构对象。

正确的JSONPath表达式

$.count_by_institution[?(@.institution.name == 'institutiona03659')]

表达式说明

  • $:指向JSON的根节点
  • .count_by_institution:定位到根节点下的count_by_institution数组
  • [?()]:JSONPath的过滤语法,用于筛选数组中符合条件的元素
  • @:指代当前遍历的数组元素
  • @.institution.name == 'institutiona03659':筛选条件,要求当前元素的institution.name属性等于目标值

查询结果

{
  "institution": {
    "id": "03659",
    "name": "institutiona03659"
  },
  "total_branches": 3
}

注:你提供的期望结果与查询需求存在矛盾(期望结果的机构名称为institutiona03629),上述为匹配需求的正确结果。

内容的提问来源于stack exchange,提问作者Bharath Sidda Reddy

相关产品推荐
方舟 Agent Plan

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

最近更新时间:2026.07.11 06:05:04