arrays - 使用 JSON 数组中另一个值的匹配来提取特定值到 JOLT

标签 arrays json jolt

我需要使用 JOLT 从该 JSON 中的“name”:“username”值中提取电子邮件地址:

我以为会这样

customer:{
      "*":{
           "name"{
                  "username":"email.@(2,value)
                 }
           }
          }

输入

{
  "customer": [
    {
      "name": "title",
      "value": "Mr"
    },
    {
      "name": "address",
      "value": "park road"
    },
    {
      "name": "username",
      "value": "<a href="https://stackoverflow.com/cdn-cgi/l/email-protection" class="__cf_email__" data-cfemail="fa9995948e9b998e8f89ba9f979b9396d4999597" rel="noreferrer noopener nofollow">[email protected]</a>"
    }
  ]
}

预期输出

{
  "email":"<a href="https://stackoverflow.com/cdn-cgi/l/email-protection" class="__cf_email__" data-cfemail="f2919d9c869391868781b2979f939b9edc919d9f" rel="noreferrer noopener nofollow">[email protected]</a>
}

最佳答案

我认为你需要一个包含这样的条件的规范

[
  {
    "operation": "shift",
    "spec": {
      "*": { // represents the array
        "*": { // represents the indexes of the array
          "name": {
            // in order to pick the desired condition 
            "username": {
              // go 2 levels up and grab the value of "value" key
              // as roaming within each objects of the main array(customer)
              // [eg. reaching the level of the indexes of the array] 
              "@(2,value)": "email" //rename the key as desired
            }
          }
        }
      }
    }
  }
]

enter image description here

关于arrays - 使用 JSON 数组中另一个值的匹配来提取特定值到 JOLT,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/69381532/

相关文章:

java - 如何将java数组列表转换为javascript数组?

python - 访问结构化数组的 NumPy 数组的列

ios - 开发iOS应用程序时从服务器获取JSON数据时包含奇怪的字符

java - 如何使用 Jolt 规范将 Json 转换为 Json?

python - Numpy 数组按值传递

java - 在 Java 中将数组排序为第二个数组

javascript - 如何将 AJAX JSON 映射到标签和值?

java - Retrofit 1.9 回调错误

jolt - 如果值不存在则设置为 null,否则如果在 jolt 中存在则返回现有值