Forum Discussion

RaymanPrince's avatar
RaymanPrince
New Contributor II
4 years ago

To replace more than one character in string by looking up another field value

I have a business requirement, where we have below JSON in that, have to update object’s field called TRANSLATION_ID by looking up another fields called VARIABLE_ID and VARIABLE_VALUE. Here if both VARIABLE_ID and VARIABLE_VALUE are not null then replace TRANSLATION_ID (say [A] to be replaceed with value in the variable value) with corresponding values present in VARIABLE_VALUE.

Note: Here currently we have max of 2 replacement values in VARIABLE_VALUE but we expect it can be more than 10.

Input json :
[
{
“PHRASE_SEQ”: 629,
“PHRASE_ID”: “[Drug Name]”,
“PLACEMENT”: “12”,
“TRANSLATION_ID”: “[Drug Name]”,
“VARIABLE_ID”: “Drug Name”,
“VARIABLE_VALUE”: “str456”
},
{
“PHRASE_SEQ”: 630,
“PHRASE_ID”: “Store at [A]°C to [B]°C”,
“PLACEMENT”: “13”,
“TRANSLATION_ID”: “Store at [A]°C to [B]°C”,
“VARIABLE_ID”: “A,B”,
“VARIABLE_VALUE”: “2,8”
}
]

Expected output would be:
[
{
“PHRASE_SEQ”: 629,
“PHRASE_ID”: “[Drug Name]”,
“PLACEMENT”: “12”,
“TRANSLATION_ID”: “str456”,
“VARIABLE_ID”: “Drug Name”,
“VARIABLE_VALUE”: “str456”
},
{
“PHRASE_SEQ”: 630,
“PHRASE_ID”: “Store at [A]°C to [B]°C”,
“PLACEMENT”: “13”,
“TRANSLATION_ID”: “Store at 2°C to 8°C”,
“VARIABLE_ID”: “A,B”,
“VARIABLE_VALUE”: “2,8”
}
]

5 Replies

  • This expression in a Mapper snap:
    $Items.Item.map(value => value.mapKeys((value, key) => "WM_" + key))

    will add the ‘WM_’ prefix to the keys for each item in this Item list.

    Having it mapped to the target Items.Item will replace the old value with your desired output.

  • sjakathi's avatar
    sjakathi
    New Contributor II

    Thanks you all for the reply it worked…