I have a requirement to iterate the below input payload and store all the EMPNAME as key and EMPID as value in Object store.
{
"application": "salesforce",
"payload": [
{
"EMPLASTNAME": "Jane",
"EMPFIRSTNAME": "Adams",
"EMPEMAIL": "[email protected]",
"EMPID": 12345,
"EMPNAME": "e76543"
},
{
"EMPLASTNAME": "Stella",
"EMPFIRSTNAME": "Benedict",
"EMPEMAIL": "[email protected]",
"EMPID": 67896,
"EMPNAME": "e34896"
},
{
"EMPLASTNAME": "Cooper",
"EMPFIRSTNAME": "Jake",
"EMPEMAIL": "[email protected]",
"EMPID": 98765,
"EMPNAME": "e11356"
}
]
}
I tried extracting the key and value pairs using the below DW code
%dw 2.0
output application/json
---
((payload.payload map {
($.EMPNAME): $.EMPID
}))
output:
[
{
"e76543": 12345
},
{
"e34896": 67896
},
{
"e11356": 98765
}
]
After this I am not able to proceed on how to put these values into Object Store (v2) as key value pairs.
I am not sure if the above DW is right way to extract the key pairs which can be used further for storing in object Store.
For example, In Object Store the key should be e76543 and value should be 12345.
Also is there a way to store the above response to a variable and update Object store in a single go
Thanks in advance
You don't need to transform that original payload. Using the Foreach Scope you can select the collection to iterate inside the payload, then use the ObjectStore connector Store operation.
Example:
As you can see in the documentation of the Object Store connector there is no store all keys operation.