cancel
Showing results forย 
Search instead forย 
Did you mean:ย 

Issues implementing a JSON payload on Workato

gmaheshwari
Deputy Chef I
Deputy Chef I

I have been creating an integration between salesforce and another system. The issue comes up when there are multiple Location Objects involved from Salesforce. How can we have dynamic Keys generated. See the snippet below to get a better idea:

{

    "destinations":{

            "0":"dest1",

            "1":"dest2"

        }

}

How would we be dealing with the dynamic number of destinations with this payload design?

 

1 ACCEPTED SOLUTION

gary1
Executive Chef III
Executive Chef III

There are different ways to handle this, but I think the simplest is to take the object into a Ruby or JS action and reformat it into something consistent and parsable.

Using your data above, this will work in a Ruby action:

 

dest = input["destinations"]

keys = dest.keys
reformat = []

keys.each { | k | 
  obj = {}
  obj["key"] = k
  obj["value"] = dest[k]
  reformat.push(obj)
}

{reformat: reformat}

 

 Output:

 

[
  {"key":"0", "value":"dest1"},
  {"key":"1", "value":"dest2"}
]

 

 

View solution in original post

1 REPLY 1

gary1
Executive Chef III
Executive Chef III

There are different ways to handle this, but I think the simplest is to take the object into a Ruby or JS action and reformat it into something consistent and parsable.

Using your data above, this will work in a Ruby action:

 

dest = input["destinations"]

keys = dest.keys
reformat = []

keys.each { | k | 
  obj = {}
  obj["key"] = k
  obj["value"] = dest[k]
  reformat.push(obj)
}

{reformat: reformat}

 

 Output:

 

[
  {"key":"0", "value":"dest1"},
  {"key":"1", "value":"dest2"}
]