最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

json - Jolt transformation to add count to event object in array object - Stack Overflow

programmeradmin2浏览0评论

Iam new to jolt. Can you please tell me how can i trasform the below json message with array based upon the position in to the below output json message using jolt.

input message :

[
  [
    "20084541",
    "12020584",
    "Frohmann Dov",
    "2017",
    "2",
    "75",
    "T7",
    "DFZ",
    "CES",
    "",
    "",
    "0",
    "90",
    "2010"
  ],
  [
    "20084541",
    "12020584",
    "Frohmann Dov",
    "2017",
    "3",
    "21",
    "T7",
    "DFZ",
    "CES",
    "",
    "",
    "0",
    "90",
    "2010"
  ]
]

output Message :

[
  {
    "policyReference": "20084541",
    "insuredId": "12020584",
    "insuredName": "Frohmann Dov",
    "uwy": "2017",
    "subLOB": "2",
    "typeOfRisk": "75",
    "aircraftcountryCode": "T7",
    "aircraftId": "DFZ",
    "manufacturerId": "CES",
    "aircraftTypeCode": "",
    "aircraftSubTypeCode": "",
    "aircraftValueAmt": "0",
    "aircraftWorkNo": "90",
    "yearBuilt": "2010",
    "count": 1
  },
  {
    "policyReference": "20084541",
    "insuredId": "12020584",
    "insuredName": "Frohmann Dov",
    "uwy": "2017",
    "subLOB": "2",
    "typeOfRisk": "75",
    "aircraftcountryCode": "T7",
    "aircraftId": "DFZ",
    "manufacturerId": "CES",
    "aircraftTypeCode": "",
    "aircraftSubTypeCode": "",
    "aircraftValueAmt": "0",
    "aircraftWorkNo": "90",
    "yearBuilt": "2010",
    "count": 2
  }
]

Just adding the count to array of elements

Iam new to jolt. Can you please tell me how can i trasform the below json message with array based upon the position in to the below output json message using jolt.

input message :

[
  [
    "20084541",
    "12020584",
    "Frohmann Dov",
    "2017",
    "2",
    "75",
    "T7",
    "DFZ",
    "CES",
    "",
    "",
    "0",
    "90",
    "2010"
  ],
  [
    "20084541",
    "12020584",
    "Frohmann Dov",
    "2017",
    "3",
    "21",
    "T7",
    "DFZ",
    "CES",
    "",
    "",
    "0",
    "90",
    "2010"
  ]
]

output Message :

[
  {
    "policyReference": "20084541",
    "insuredId": "12020584",
    "insuredName": "Frohmann Dov",
    "uwy": "2017",
    "subLOB": "2",
    "typeOfRisk": "75",
    "aircraftcountryCode": "T7",
    "aircraftId": "DFZ",
    "manufacturerId": "CES",
    "aircraftTypeCode": "",
    "aircraftSubTypeCode": "",
    "aircraftValueAmt": "0",
    "aircraftWorkNo": "90",
    "yearBuilt": "2010",
    "count": 1
  },
  {
    "policyReference": "20084541",
    "insuredId": "12020584",
    "insuredName": "Frohmann Dov",
    "uwy": "2017",
    "subLOB": "2",
    "typeOfRisk": "75",
    "aircraftcountryCode": "T7",
    "aircraftId": "DFZ",
    "manufacturerId": "CES",
    "aircraftTypeCode": "",
    "aircraftSubTypeCode": "",
    "aircraftValueAmt": "0",
    "aircraftWorkNo": "90",
    "yearBuilt": "2010",
    "count": 2
  }
]

Just adding the count to array of elements

Share Improve this question edited Nov 18, 2024 at 11:22 Barbaros Özhan 65.6k11 gold badges36 silver badges62 bronze badges asked Nov 18, 2024 at 11:20 vyshnavi damavyshnavi dama 11 silver badge
Add a comment  | 

1 Answer 1

Reset to default 1

You can use the following transformation spec :

[
  {
    "operation": "shift",
    "spec": {
      "*": {
        "0": "[&1].policyReference",
        "1": "[&1].insuredId",
        "2": "[&1].insuredName",
        "3": "[&1].uwy",
        "4": "[&1].subLOB",
        "5": "[&1].typeOfRisk",
        "6": "[&1].aircraftcountryCode",
        "7": "[&1].aircraftId",
        "8": "[&1].manufacturerId",
        "9": "[&1].aircraftTypeCode",
        "10": "[&1].aircraftSubTypeCode",
        "11": "[&1].aircraftValueAmt",
        "12": "[&1].aircraftWorkNo",
        "13": "[&1].yearBuilt",
        "$": "[&1].count"
      }
    }
  },
  {//originally indexes starts from zero, so need to increment them by one
    "operation": "modify-overwrite-beta",
    "spec": {
      "*": {
        "count": "=intSum(1,@(1,&))"
      }
    }
  }
]
发布评论

评论列表(0)

  1. 暂无评论