I’m trying to replace a json element in a large block returned from an API call. The JSON structure is variable between calls but I know the exact element I am trying to replace. From what I can tell the easiest way to do this is with the String Manipulation node RegexReplace.
Given a JSON body that looks like this (most of the body omitted for clarity):
...
, {
“name” : “part number”,
“value” : “99”
}, {
“name” : “quantity”,
“value” : "9.0 "
}, {
“name” : “quantityUnit”,
“value” : “each”
},
...
I’m using the RegexReplace function but it does not seem to work. In the below example I’m attempting to replace the capture group $1 by “35.3”.
regexReplace($body$, "(\"name\"\s*\:\s*\"quantity\",\s*\"value\"\s*\:\s)\"(.*)\",", join("$1","\"35.3\","))
Unfortunately this replace does not seem to work. The result is that I return the exact same JSON that was in $body$
If I use the same regular expression in the Palladian Regex Extractor node it works as expected and I can extract the quantity value of “9.0” from the $body$
Am I using the RegexReplace function correctly? Is there some trick to accessing the capture groups?