I have request below sample json payloads.
Payload 1:
[{
"ProdTabName": {
"0": "Prod Creation/Maintenance",
"1": "Client Goals"
},
"ProdOwner": "abcd123"
}]
Payload 2:
[{
"ProdTabName": "Home Page",
"ProdOwner": "abcd123"
}]
I am expecting output payload like below:
ExpectedOutput:
{
"ProdType": ["Prod Creation/Maintenance, Prod Types"],
"ProdHomeOwner": "abcd123"
}
In the request JSON payloads, sometimes i received ProdTabName value as list (ex: payload 1), and sometimes receives normal value (ex: payload 2).
But i need to transform into ExpectedOutput payload. Can anyone please help.
Your expected output seems to be incorrect .
If your output is expected sth like below in case ProdTabName is an Object instead of String:
[
{
"ProdType": [
"Prod Creation/Maintenance",
"Client Goals"
],
"ProdHomeOwner": "abcd123"
}
]
Try below:
payload map
{
"ProdType": ($.ProdTabName pluck $) when ((typeOf ($.ProdTabName)) as :string == ":object")
otherwise $.ProdTabName,
"ProdHomeOwner": $.ProdOwner
}
In case of String it will not create an Array, simply map the string.