Count Boxer
Count Boxer

Reputation: 703

Iterating over an array of objects using DataWeave

I have an single element array with multiple objects:

[
  {
    "date": "8/5/2020",
    "cost": "11.70",
    "weight": "5.15",
    "shipVia": "FEDEX_GROUND",
    "costCenter": "004710 Somewhere Center",
    "oblpn": "202008041135387011898-1",
    "trackingNumber": "171423390688"
  },
  {
    "date": "8/5/2020",
    "cost": "8.58",
    "weight": "4.35",
    "shipVia": "FEDEX_GROUND",
    "costCenter": "004710 Somewhere Center",
    "oblpn": "2020080412204106866847-1",
    "trackingNumber": "171423390699"
  },
  {
    "date": "8/5/2020",
    "cost": "10.10",
    "weight": "12.30",
    "shipVia": "FEDEX_GROUND",
    "costCenter": "004710 Somewhere Center",
    "oblpn": "202008040835402031091-1",
    "trackingNumber": "171423390703"
  },
  {
    "date": "8/5/2020",
    "cost": "12.23",
    "weight": "3.20",
    "shipVia": "FEDEX_GROUND",
    "costCenter": "004710 Somewhere Center",
    "oblpn": "2020080414353759677658-1",
    "trackingNumber": "171423390714"
  }
]

I thought that a For Each module would allow me to walk through each object one at a time, but I can't figure out what to use in the 'Collection' field of the For Each module. The object doesn't have a name so how do I refer to it?

Upvotes: 0

Views: 1018

Answers (1)

Janardan Kelkar
Janardan Kelkar

Reputation: 170

You would just use the variable (vars.myArray) which contains this json array in the Collection field. In case this is your payload, you can write payload or simply leave it empty.

Upvotes: 2

Related Questions