[SR-Users] Question about parsing a jsonrpc_exec result with a colon in object name with jansson_get

jenus at cyberchaos.nl jenus at cyberchaos.nl
Thu Dec 7 10:27:54 CET 2017


Hi all,

I'm trying to parse the result of a json rpc call to get the register 
statistics.


# Get registrar stats
jsonrpc_exec('{"jsonrpc": "2.0", "method": "stats.get_statistics", 
"params": ["accepted_regs"], "id": 1}');
jansson_get("result[0]", $jsonrpl(body), "$var(registrar_accepted)");
xlog("LOG_LOCAL3","L_WARN","$jsonrpl(body)\n");

The $jsonrpl(body) var contains: 
{"jsonrpc":"2.0","result":["registrar:accepted_regs = 2"],"id":1}


With this code the result stored in $var(registrar_accepted) is : 
"AcceptedRegistrations":"registrar:accepted_regs = 1"

I'm trying to get only the value. I have tried:

jansson_get("result[0].registrar:accepted_regs", $jsonrpl(body), 
"$var(registrar_accepted)");
jansson_get("result[0].['registrar:accepted_regs']", $jsonrpl(body), 
"$var(registrar_accepted)");
jansson_get("result[0]['registrar:accepted_regs']", $jsonrpl(body), 
"$var(registrar_accepted)");

But this does not work. Do i need to escape the colon in the object name 
"registrar:accepted_regs" ?

Thanks,

Jan



More information about the sr-users mailing list