Implement a Counter in Dataweave

These days, I see quite a few posts that require using Counter in DataWeave. The problem faced is that users require a Sequence Number that is consistent throughout the different sections of data. Consider the below JSON:

JSON

xxxxxxxxxx
1

17

 

1

[{

2

"Item" : "ItemXYZ",

3

  "SequenceNo" : 1,

4

  "Parts": [

5

{ "Part" : "A1", "SequenceNo" : 2 }, { "Part" : "B1", "SequenceNo" : 3 },

6

{ "Part" : "A2", "SequenceNo" : 4 }, { "Part" : "B2", "SequenceNo" : 5 }

7

  ]

8

},

9

 {

10

"Item" : "ItemRTY",

11

  "SequenceNo" : 6,

12

  "Parts": [

13

{ "Part" : "A1", "SequenceNo" : 7 }, { "Part" : "B1", "SequenceNo" : 8 },

14

{ "Part" : "A2", "SequenceNo" : 9 }, { "Part" : "B2", "SequenceNo" : 10 }

15

  ]

16

}

17

]


Source link