如何使用JSON路径解析器遍历JSON?

时间:2014-06-16 21:58:18

标签: json jsonpath

我有以下JSON响应

 '{ "person_list":
 [

  {
"id": "4",
"demographics": {
  "address": {
    "city": "Tokyo",
    "country": "Japan",
    "county_or_parish": "some county",
    "postal_code": "98765",
    "state_or_province": "some state",
    "street_addresses": [
      "123 Some Street"
    ]
  },
  "date_of_birth": "1964-01-30T00:00:00.000Z",
  "date_of_death": "2013-01-30T00:00:00.000Z",
  "deceased": true,
  "emails": [],
  "gender": "Male",
  "full_name": "Yagami Light M",
  "given_names": [
    "Light",
    "Maes"
  ],
  "family_names": [
    "Yagami",
    "Hughes"
  ],
  "prefix": "Dr.",
  "suffix": "Jr.",
  "telecoms": [],
  "mrn_aliases": [],
  "payer_info": [],
  "person_benefit_coverages": []
},
"mara_risk_scores": [
  {
    "score": 10.0,
    "model": "CXCONLAG0"
  },
  {
    "score": 20.0,
    "model": "CXCONLAG1"
  },
  {
    "score": 30.0,
    "model": "CXCONLAG2"
  }
    ],
   "dashboard": {},
   "has_flagged_manual_data": true,
   "record_ids": []
 },
  {
  "id": "3",
  "demographics": {
  "emails": [],
  "given_names": [],
  "family_names": [],
  "telecoms": [],
  "mrn_aliases": [],
  "payer_info": [],
  "person_benefit_coverages": []
  },
  "mara_risk_scores": [],
   "dashboard": {},
   "has_flagged_manual_data": false,
  "record_ids": []
    }
   ]
  }'

现在我想得到id的人口统计信息,它等于我从​​另一个对象检索到的empi_id ..

我试过这个..             JsonPath.read(jsonObject,“$。person_list [] .demographics”,filter(where(“id”)。eq(cs.getEmpiId())))

它似乎无法工作..你能帮助我吗?

1 个答案:

答案 0 :(得分:1)

此JSONPath表达式可以帮助您获得所需内容:

$.person_list[?(@.id=='4')].demographics

将4替换为您感兴趣的人的身份证明,并且它应该可以解决问题。