I need to extract key and values from json input object to form different json output.
I went through the documentation and other questions asked similar to this where I could found out that $$ gives the key but, in my case it is giving me index but not the key name.
The input json looks like this :{
"key2": "val2",
"key3": "val3",
"key4": "val4",
"key5": "val5",
"key6": "val6"
}
The dataweave code I have written is :
{
"someOtherKey": "val",
properties: {
entry: payload map
{
key:$$,
value:$
}
}
}
After transformation I am getting :
{
"someOtherKey": "val",
"properties": {
"entry": [
{
"key": 0,
"value": "val2"
},
{
"key": 1,
"value": "val3"
},
{
"key": 2,
"value": "val4"
},
{
"key": 3,
"value": "val5"
},
{
"key": 4,
"value": "val6"
}
]
}
}
Here I am expecting output with key name as value for Key
Expected output :
{
"someOtherKey": "val",
"properties": {
"entry": [{
"key": "key2",
"value": "val2"
},
{
"key": "key3",
"value": "val3"
},
{
"key": "key4",
"value": "val4"
},
{
"key": "key5",
"value": "val5"
},
{
"key": "key6",
"value": "val6"
}
]
}
}