0

I am fetching data from database and trying to assigning using dataweave. However, I see if there are multiple values fetch for a query then it is combining all the values of column into single array.

Currently with the my dataweave logic it is return me this output

Current Output:

"orders": [
        {
          "orderID": "[10355, 10383, 10453]",
          "employeeID": "[6, 8, 1]"
        }
      ]

Expected Output:

"orders": [
            {
              "orderID": "103553",
              "employeeID": "6"
            },
            {
              "orderID": "10383",
              "employeeID": "8"
            },
            {
              "orderID": "10453",
              "employeeID": "1"
            }
          ]

Thanks in advance

1
  • What is the input and your current script? Commented May 22, 2020 at 17:15

1 Answer 1

1

You can change String to JSON on the fly and then use it https://simpleflatservice.com/mule4/ChangeStringToJsonOnTheFly.html

%dw 2.0
var x={"orders": [
        {
          "orderID": "[10355, 10383, 10453]",
          "employeeID": "[6, 8, 1]"
        }
      ]    
}
output application/json
---
{
    orders: read(x.orders[0].orderID,'application/json') map (item,index) ->
    {
        orderID:item, 
        "employeeID": read(x.orders[0].employeeID,'application/json')[index]
    }
}

output

{
  "orders": [
    {
      "orderID": 10355,
      "employeeID": 6
    },
    {
      "orderID": 10383,
      "employeeID": 8
    },
    {
      "orderID": 10453,
      "employeeID": 1
    }
  ]
}
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.