Hi guys,
I'm calling a target endpoint from which I get some XML data in a format similar to the one below:
PAYLOAD 1:
<rooms> <room> <id>1</id> <name>...</name> </room> <room> <id>1</id> <name>...</name> </room> ... <room> <id>N</id> <name>...</name> </room> </rooms>
Then I do a callout from which I get some JSON data:
PAYLOAD 2
{ { "id": 1, "type": XXXXX }, { "id": 2, "type": XXXXX }, ... { "id": N, "type": XXXXX } }
The id's from payloads 1 and 2 are correlated. What I want is to enrich the payload 1 with the "type" element from payload 2, so that in the end I return a JSON in the format:
DESIRED FINAL PAYLOAD:
{ "rooms": { "room": [ { "id": 1, "name": XXXXX "type": XXXXX }, { "id": 2, "name": XXXXX "type": XXXXX }, ... { "id": N, "name": XXXXX "type": XXXXX } ] } }
I know translating from XML to Json is trivial, but I'm not sure which policy I should use to enrich the payload. I thought transforming payload 2 to XML, then use a XSL policy to enrich the XML, then finally transform everything to JSON again. But it seemed a rather clunky solution, and I'm not even sure if that's possible with XSL (I don't have much experience with XSL).
So, any suggestions on the best approach here? Will I have to do it all manually with javascript?
Thanks!
Yes, you need to use Javascript there is no OOTB policy to do this.
Use both responses as JSOn and use JS
User | Count |
---|---|
1 | |
1 | |
1 | |
1 | |
1 |