简体   繁体   中英

transformation of nested array in array by jolt

I have following JSON data . I want to transform following data by Jolt nifi processor into result data

{
  "alert_array": {
    "alerts": [
      {
        "alertId": "alt001",
        "severity": "High",
        "alert_type": "Alert"
      },
      {
        "alertId": "alt002",
        "severity": "High",
        "alert_type": "Alert"
      }
    ]
  }
}

result data

{
  "alert_array": [
    {
      "Id": "alt001",
      "speed": "High",
      "type": "Alert"
    },
    {
      "Id": "alt002",
      "speed": "High",
      "type": "Alert"
    }
  ]
}

please help to write spac of jolt transformation

If you wouldn't rename the attributes, then using

[
  {
    "operation": "shift",
    "spec": {
      "*": {
        "*": {
          "*": "&2[&]"  // &2 represents going two levels up to get the literal "alert_array"
        }
      }
    }
  }
]

would suffice.

the demo on the site http://jolt-demo.appspot.com/ is

在此处输入图像描述

But in your case, you need to qualify each one individually such as

[
  {
    "operation": "shift",
    "spec": {
      "*": {
        "*": {
          "*": {
            "alert*": "&3[&1].&(0,1)",
            "severity": "&3[&1].speed",
            "alert_*": "&3[&1].&(0,1)"
          }
        }
      }
    }
  }
]

the demo on the site http://jolt-demo.appspot.com/ is

在此处输入图像描述

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM