Hi Folks - I am using JANSSON to store JSON data in an htable. How does one remove an entire element from a JSON?
I do not see a specific function mentioning clear or remove exposed in the Kamailio module, but do see various clear/remove methods in the underlying C library.
Below does set the value of key foo to null. I would like to remove both the key and value of foo.
jansson_set("null", "$var(foo)", "$var(json)", "$var(result)");
Running Kamailio v5.4 Debian 10
-Jeremy
Hello,
I haven't looked and jansson module, maybe it needs an extension for it, if nobody needed the operation so far, but I just want to point that whenever I needed a bit more complex JSON operations, I just used an embedded scripting language like javascript (app_jsdt) or lua (app_lua). You can pass the entire json as a string parameter, transform it, then serialized it back to a Kamailio variable.
Cheers, Daniel
On 20.03.21 23:09, Jeremy McNamara wrote:
Hi Folks - I am using JANSSON to store JSON data in an htable. How does one remove an entire element from a JSON?
I do not see a specific function mentioning clear or remove exposed in the Kamailio module, but do see various clear/remove methods in the underlying C library.
Below does set the value of key foo to null. I would like to remove both the key and value of foo.
jansson_set("null", "$var(foo)", "$var(json)", "$var(result)");
Running Kamailio v5.4 Debian 10
-Jeremy
Kamailio (SER) - Users Mailing List sr-users@lists.kamailio.org https://lists.kamailio.org/cgi-bin/mailman/listinfo/sr-users
Hi Daniel - Thank you I will look into that. Is it possible with KEMI to delegate individual route[] blocks into KEMI but leave others as kamailio.cfg native?
For example, make all of my registration attempts get handled by KEMI, but the rest of the operations still live in kamailio.cfg.
-Jeremy
Hello,
you can combine the two modes, there are functions exported by each KEMI module that you can run snippets of code from native kamailio.cfg route blocks.
For example, you keep the native scripting kamailio.cfg, then with app_jsdt (load parameter) you can have the js script like:
function ksr_json_update() { var rtdoc = ""; var rtobj;
rtdoc = KSR.pv.gete("$var(json)"); rtobj = JSON.parse(rtdoc);
// update the rtobj ...
KSR.pv.sets("$var(json)", JSON.stringify(rtobj)); }
Then, in the route blocks of kamailio.cfg:
$var(json) = '{"x": "a"}'; if(!jsdt_run("ksr_json_update")) { xlog("failed to execute js function\n"); }
xinfo("new json: $var(json)\n");
KSR object is available, like in the case of having the routing blocks written entirely in the javascript.
Then, the other way around is possible as well, write the routing blocks in javascript (or lua, ...) and still define route[ABC] in kamailio.cfg which can be executed with KSR.route("ABC") from the KEMI script.
Cheers, Daniel
On 22.03.21 15:08, Jeremy McNamara wrote:
Hi Daniel - Thank you I will look into that. Is it possible with KEMI to delegate individual route[] blocks into KEMI but leave others as kamailio.cfg native?
For example, make all of my registration attempts get handled by KEMI, but the rest of the operations still live in kamailio.cfg.
-Jeremy
Kamailio (SER) - Users Mailing List sr-users@lists.kamailio.org https://lists.kamailio.org/cgi-bin/mailman/listinfo/sr-users