【问题标题】:Select a JSON attribute based on other elements within an array using JSONPath使用 JSONPath 根据数组中的其他元素选择 JSON 属性
【发布时间】:2020-02-11 21:20:05
【问题描述】:

我有一个示例 JSON 数组:

{
"data": {
    "list": [
        {
            "id": 192,
            "name": "John Black",
            "username": "jblack",
            "email": "jblack@myorganization.com",
            "extern_uid": "user distinguished name"
        },
        {
            "id": 63,
            "name": "Jane Doe",
            "username": "jadoe",
            "email": "jadoe@myorganization.com",
            "extern_uid": "user distinguished name"
        }
    ]
}}

我想使用 JSONPath 表达式基于另一个属性提取一个属性,

例如:

我想搜索名称“Jane Doe”并从 Jane Doe 数组中提取值,例如 id: 63 或 Jane Doe 数组中的任何其他值。这在 JSONPath 中可能吗?我不是 JSONPath 方面的专家,所以如果这对其他人来说似乎微不足道,我深表歉意

谢谢大家

【问题讨论】:

    标签: arrays json json-path-expression


    【解决方案1】:

    找到解决方案:

    $.data.list[?(@.username == "jblack")].id

    将返回:

    “id”:192

    【讨论】:

      猜你喜欢
      • 2013-08-23
      • 2011-03-11
      • 1970-01-01
      • 2012-10-08
      • 1970-01-01
      • 2010-09-18
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多