如何使用 JMESPath 根据子属性数组中包含的值过滤对象数组

How to use JMESPath to filter array of object based on contains of value in subproperty arrary

如何使用JMESPath 来过滤具有确切电子邮件收件人的节点? 我有 JSON 个对象:

   [     
     {
        "test":1,
        "emailReceivers": [
          {
            "emailAddress": "a1@abc.com",
          }
        ]
      },
      {
        "test":2,
        "emailReceivers": [
          {
            "emailAddress": "a2@abc.com",
          },
          {
            "emailAddress": "a3@abc.com",
          }
        ]
      }
    ]

我想通过包含 a1@abc.com:

的 elememailReceivers 过滤后获取节点
     {
        "test":1,
        "emailReceivers": [
          {
            "emailAddress": "a1@abc.com",
          }
        ]
      }

我尝试使用文档 https://jmespath.org/ 和示例,但失败了。

您确实可以在过滤器上使用 contains 并询问包含特定值的子键。

随查询

[?contains(emailReceivers[].emailAddress, 'a1@abc.com')]

这将得到:

[
  {
    "test": 1,
    "emailReceivers": [
      {
        "emailAddress": "a1@abc.com"
      }
    ]
  }
]

在您的示例数组中:

[     
  {
    "test":1,
    "emailReceivers": [
      {
        "emailAddress": "a1@abc.com"
      }
    ]
  },
  {
    "test":2,
    "emailReceivers": [
      {
        "emailAddress": "a2@abc.com"
      },
      {
        "emailAddress": "a3@abc.com"
      }
    ]
  }
]