The Reltio Integration Hub (RIH) provides an excellent JSON parser. To use it, you simply click the plus sign to add an element to your recipe and select ‘Action in App’. When you do this the possible actions are on the right and you can select ‘JSON Parser by Workato’. The configurator is then able to paste a sample JSON message into the parser so RIH understands its structure and finally the configurator points to the part of the recipe that is used as the input. This is done in the ‘Document’ part of the screen. Once this is done, RIH parses the json and the particular bit of the JSON you are looking for is available in the pop up in subsequent steps. It’s actually harder to write about it than it is to use it: it’s so simple!
Unless…..
I recently ran into a message that looked like this:
{
"type": "POTENTIAL_LINK_FOUND",
"sourceObjectUri": "entities/0000QvR",
"matches": {
"entities/00iOwAp": [
"configuration/entityTypes/customMatchAction/matchGroups/PotentialLink"
]
}
}
What I needed from the message was the two entity id’s. The sourseObjectUri was easy because after using the RIH JSON parser, it was a data pill I could drag and drop directly into the input field of the recipe. However, the second entity id comes after the matches and is in what is known as a ‘key’ in JSON. The message is structured this way because there could have been more than one match, although in this case only one is shown. (as a side note, if there was more than one, the ‘entities/00iOwAp’ would be repeated with the other entity id. What’s in the array that follows is the URI of the match rule(s) that found the duplicate.)
Unfortunately, the key is not available directly from the parser as a data pill. However, it IS available via writing a little bit of code. As you may know, RIH uses Ruby as a scripting language. And fortunately, Ruby has a .keys function which will pick this value out. Ruby also has a ‘safe’ operator .& which is known as the ‘safe navigation operator’. This does not do the parsing if the value is nil which would return an error. Putting this all together, the configurator can use the data pill from the JSON parser to drop the ‘matches’ object into the target and then add the .& to make sure it's not nil. In my case, only the first key was needed and the ‘entities’ part of the URI was not needed, so a parsing of just the bit after the slash was added. The final configuration looks like this:
and the output is 00iOwAp.
Hopefully, this post will help someone trying to figure out how to get to a key in a Reltio message! Huge shout out to to Alexander Grivnin of workato.
A couple of reference notes:
https://stackoverflow.com/questions/36812647/what-does-ampersand-dot-mean-in-ruby
https://stackoverflow.com/questions/8657740/ruby-get-object-keys-as-array
#Blog