2

I am running Mule 3 and is on dataweave 1.0 I have a JSON payload (with dynamic key and value) which occurs inside a For Each loop. Sample data is given below:

{
  "094d29c7-6abf-4acb-8513-e1d2d2b8998a": "900145600114256"
}

The key is UUID and value is an Identifier. I need to store the value in a sessionVar. Can someone help me with the dataweave 1.0 to extract the JSON value (900145600114256) from above? Thanks in advance.

Triumph Spitfire
  • 663
  • 15
  • 38

2 Answers2

5

I would use the pluck operator. This will go through each key value pair. In this case you would get the list of values

(payload pluck ((value,key) -> value))[0]
machaval
  • 4,969
  • 14
  • 20
1

It looks like you do mot know what keys could be in your object. mapObject function helps with this issue

%dw 2.0
var x={
  "094d29c7-6abf-4acb-8513-e1d2d2b8998a": "900145600114256"
}
output application/json
---
x mapObject ((value, key, index) ->
    {keyFromPaylod:key, valueFromPayload: value}
)

Preview

See how to work with unknown keys here https://simpleflatservice.com/mule4/WorkingWithUnknownKeys.html

Alex
  • 4,457
  • 2
  • 20
  • 59