Forum Discussion
Lee_Sutcliffe
May 17, 2019Nacreous
There's a couple of ways you can do this, if the POST is JSON like you say, the easiest way (in my opinion) is to use iRules LX. iRules LX is essentially Node.js which is server side JavaScript.
I wrote a code share article on reading in JSON body and modifying the values of some of the keys. You can take a similar approach to add new key pair values
https://devcentral.f5.com/s/articles/simple-iruleslx-json-rewrite-1196
The alternative, is to read in the body as before and look for unique bit of code, then using ```string map``` to replace replace this code with the bit you were looking for + the new inserted bit.
Also remember to rewrite your Content-Length header.
Hopefully this will be enough to get you going:
set payload [HTTP::payload]
set find "\"key1\": \"value1\""
set insert "$find, \"key2\": \"value2\""
set newPayload [string map [list "$find" "$inset"] $payload ]
HTTP::payload replace 0 [HTTP::header "Content-Length"] $newPayload
Good Luck!
Lee