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
相关产品推荐
相关产品推荐

