最新消息:Welcome to the puzzle paradise for programmers! Here, a well-designed puzzle awaits you. From code logic puzzles to algorithmic challenges, each level is closely centered on the programmer's expertise and skills. Whether you're a novice programmer or an experienced tech guru, you'll find your own challenges on this site. In the process of solving puzzles, you can not only exercise your thinking skills, but also deepen your understanding and application of programming knowledge. Come to start this puzzle journey full of wisdom and challenges, with many programmers to compete with each other and show your programming wisdom! Translated with DeepL.com (free version)

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

matteradmin3PV0评论

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,&))"
      }
    }
  }
]
Post a comment

comment list (0)

  1. No comments so far