Forum Discussion
David_Simmons
Nimbostratus
Mar 30, 2018string map with variables including quotes
I'm trying to do some irule manipulation of JSON payload data and in specific cases add a couple of fields to the payload. At this point, I'm simply logging my changes but once I validate that this ...
Stanislas_Piro2
Cumulonimbus
Mar 31, 2018Look at this in tclsh (shell available on most of linux OS and also on bigip)
Your command :
$ tclsh
% set payload "\{\"parameter1\":\"value1\",\"Phone\":\"7345551212\",\"parameter2\":\"value2\"\}"
{"parameter1":"value1","Phone":"7345551212","parameter2":"value2"}
% set searchvalue "\"Phone\":\"7345551212\","
"Phone":"7345551212",
% set replacevalue "\"Phone\":\"7345551212\",\"TestData\":\"Yes\","
"Phone":"7345551212","TestData":"Yes",
% string map "${searchvalue} ${replacevalue}" ${payload}
list element in quotes followed by ":"7345551212"," instead of space
with search / replace strings between curly brackets:
$ tclsh
% set payload "\{\"parameter1\":\"value1\",\"Phone\":\"7345551212\",\"parameter2\":\"value2\"\}"
{"parameter1":"value1","Phone":"7345551212","parameter2":"value2"}
% set searchvalue {\"Phone\":\"7345551212\",}
\"Phone\":\"7345551212\",
% set replacevalue {\"Phone\":\"7345551212\",\"TestData\":\"Yes\",}
\"Phone\":\"7345551212\",\"TestData\":\"Yes\",
% string map "${searchvalue} ${replacevalue}" ${payload}
{"parameter1":"value1","Phone":"7345551212","TestData":"Yes","parameter2":"value2"}
or with string map list created before (with curly brackets)
$ tclsh
% set payload "\{\"parameter1\":\"value1\",\"Phone\":\"7345551212\",\"parameter2\":\"value2\"\}"
{"parameter1":"value1","Phone":"7345551212","parameter2":"value2"}
% set stringmap {"\"Phone\":\"7345551212\"," "\"Phone\":\"7345551212\",\"TestData\":\"Yes\","}
"\"Phone\":\"7345551212\"," "\"Phone\":\"7345551212\",\"TestData\":\"Yes\","
% string map $stringmap ${payload}
{"parameter1":"value1","Phone":"7345551212","TestData":"Yes","parameter2":"value2"}
or with string map list created before (with list command)
$ tclsh
% set payload "\{\"parameter1\":\"value1\",\"Phone\":\"7345551212\",\"parameter2\":\"value2\"\}"
{"parameter1":"value1","Phone":"7345551212","parameter2":"value2"}
set stringmap [list "\"Phone\":\"7345551212\"," "\"Phone\":\"7345551212\",\"TestData\":\"Yes\","]
{"Phone":"7345551212",} {"Phone":"7345551212","TestData":"Yes",}
% string map $stringmap ${payload}
{"parameter1":"value1","Phone":"7345551212","TestData":"Yes","parameter2":"value2"}
%
or with string map list created before (from searchvalue variable)
$ tclsh
% set payload "\{\"parameter1\":\"value1\",\"Phone\":\"7345551212\",\"parameter2\":\"value2\"\}"
{"parameter1":"value1","Phone":"7345551212","parameter2":"value2"}
% set searchvalue "\"Phone\":\"7345551212\","
"Phone":"7345551212",
% set stringmap [list $searchvalue $searchvalue"\"Phone\":\"7345551212\",\"TestData\":\"Yes\","]
{"Phone":"7345551212",} {"Phone":"7345551212",""Phone":"7345551212","TestData":"Yes","}
% string map $stringmap ${payload}
{"parameter1":"value1","Phone":"7345551212",""Phone":"7345551212","TestData":"Yes",""parameter2":"value2"}
Recent Discussions
Related Content
DevCentral Quicklinks
* Getting Started on DevCentral
* Community Guidelines
* Community Terms of Use / EULA
* Community Ranking Explained
* Community Resources
* Contact the DevCentral Team
* Update MFA on account.f5.com
Discover DevCentral Connects