Search code examples
muledataweavemulesoftmule4

dataweave mapping from an array


I have a basic dataweave mapping function. I want to have a number of objects with a simple array as input: I have created the function generatePoints to achive this


fun generatePoints() = [1 to 24] map {
        currentyear: 2023,
        points: $[$$],
}

It returns a single array:

[
  {
    "currentyear": 2023,
    "points": 1
  }
]

But it should return something like this:

[
  {
    "currentyear": 2023,
    "points": 1
  },
  {
    "currentyear": 2023,
    "points": 2
  },
  {
    "currentyear": 2023,
    "points": 3
  }
.....
  {
    "currentyear": 2023,
    "points": n
  }
]

Does anybody know how to update the generatePoints function to achieve this ?


Solution

  • 1 to 24 is already a range with type array. Therefore you have to remove the [] around it. As it is creating an Array with a single "array" element.