0
votes

I want to do the below transformation using mule Dataweave transformation. The input is a array of JSON key value pairs. I need to split the same.

Input

{
   "order":[
      {
         "key":"Status",
         "value":"Completed"
      },
      {
         "key":"Source",
         "value":"internet"
      },
      {
         "key":"name",
         "value":"abc def"
      },
      {
         "key":"domain",
         "value":"insurance"
      }
   ]
}

Output

 {
   "order":[
      {
         "key":"Status",
         "value":"Completed"
      },
      {
         "key":"Source",
         "value":"internet"
      }
   ],
   "Name":[
      {
         "key":"name",
         "value":"abc def"
      },
      {
         "key":"domain",
         "value":"insurance"
      }
   ]
}

Can anyone help?

1

1 Answers

0
votes

You can do that by filtering input on the basis of keys

%dw 1.0
%output application/json
%var data = ["name","domain"]
---
{
    order : payload.order filter not (data contains $.key),
    Name :  payload.order filter  (data contains $.key)
}

Hope this helps.