Hi @Krzysztof Nowicki,
Below is the design which does the ask:
Firstly, I had set the string variable as below:
Then in JavaScript Action, used below code:
function rithreplacefunc(jsonString) {
const ri_match = jsonString.match(/"Special_Instructions"\s*:\s*"(.*?)"(\s*,\s*"\w+":)/s);
if (ri_match) {
let gotVal = ri_match[1];
let choVal = gotVal.replace(/"/g, '\\"');
let evalue = choVal.replace(/\n/g, '\\n')
return jsonString.replace(ri_match[0], `"Special_Instructions": "${evalue}"${ri_match[2]}`);
}
throw new Error("Hello Rithwik, Special_Instructions property not found in the given JSON string.");
}
let cho_ri_data = workflowContext.actions.Set_variable.inputs.value;
if (!cho_ri_data || typeof cho_ri_data !== "string") {
throw new Error("Hello Rithwik, Set_variable.inputs.value is undefined, incorrect, or not a JSON string.");
}
let riout = rithreplacefunc(cho_ri_data);
return riout;
Output:
Hope this helps.
If the answer is helpful, please click Accept Answer and kindly upvote it. If you have any further questions about this answer, please click Comment.