[SR-Users] JANSSON module not working for multiple JSON objects

vivek at advaitamtech.com vivek at advaitamtech.com
Thu Apr 27 12:39:01 CEST 2017


Thank you for the suggestion. It worked with array and i could parse successfully. 
 
Thanks,
Vivek.
 
-----Original Message-----
From: "Daniel-Constantin Mierla" <miconda at gmail.com>
Sent: Wednesday, 26 April, 2017 11:30am
To: "vivek at advaitamtech.com" <vivek at advaitamtech.com>
Cc: "Kamailio (SER) - Users Mailing List" <sr-users at lists.kamailio.org>
Subject: Re: [SR-Users] JANSSON module not working for multiple JSON objects



I haven't developed the module, will have to look at the code, but I would expect to work for the array object, given it relies on libjansson external library.
Maybe you can try with:$avp(result1)="{\"a\":[{\"origin\":\"125.16.231.74\",\"Dest\":\"725.76.731.77\"}]}";

 just to see if it works and there is no problem parsing that array, but the problem is having an array as root object.

 Cheers,
 Daniel



On 26.04.17 07:51, [ vivek at advaitamtech.com ]( mailto:vivek at advaitamtech.com ) wrote:
There are no error messages for the below test JSON object. Let me give you a clear picture,
 
$avp(result1)="{\"origin\":\"125.16.231.74\",\"Dest\":\"725.76.731.77\"}" --> Successfully parsed and result is recevied.
 
$avp(result1)="[{\"origin\":\"125.16.231.74\",\"Dest\":\"725.76.731.77\"}]"; --> No Error and no parsed result either.
 
$avp(result1)="{\"origin\":\"125.16.231.74\",\"Dest\":\"725.76.731.77\"},{\"origin\":\"225.26.231.24\",\"Dest\":\"225.26.231.27\"}"; --> Results in error.
   ERROR: jansson [jansson_funcs.c:59]: janssonmod_get(): failed to parse:  {"origin":"125.16.231.74","Dest":"725.76.731.77"},{"origin":"225.26.231.24","Dest":"225.26.231.27"}
 ERROR: jansson [jansson_funcs.c:61]: janssonmod_get(): json error at line 1: end of file expected near ','
$avp(result1)="[{\"origin\":\"125.16.231.74\",\"Dest\":\"725.76.731.77\"},{\"origin\":\"225.26.231.24\",\"Dest\":\"225.26.231.27\"}]" --> No error. But no result either. GIves result as zero.
 
I understand that with "[ ]" , its the right JSON object. But api doesnt give the parsed result.
 
Thanks,
Vivek.
 
-----Original Message-----
 From: "Daniel-Constantin Mierla" [ <miconda at gmail.com> ]( mailto:miconda at gmail.com )
 Sent: Tuesday, 25 April, 2017 7:47pm
 To: "Kamailio (SER) - Users Mailing List" [ <sr-users at lists.kamailio.org> ]( mailto:sr-users at lists.kamailio.org ), [ sr-users at lists.sip-router.org ]( mailto:sr-users at lists.sip-router.org )
 Subject: Re: [SR-Users] JANSSON module not working for multiple JSON objects



Hello,

On 25.04.17 15:57, [ vivek at advaitamtech.com ]( mailto:vivek at advaitamtech.com ) wrote:
Hi All,
 
Am using JANSSON module to parse the JSON object I receive.
 
I tried using JSON module of kamailio. Since its giving error in loading the module due to  error"libjson-c.so.3: cannot open shared object file: No such file or directory", I went ahead to use JANSSON module.
 
JANSSON module is parsing the single JSON object perfectly. But not parsing the multiple JSON objects.
 
JSON object am trying to parse:
$avp(result1)= "[{"origin":"125.16.231.74","Dest":"725.76.731.77"},{"origin":"225.26.231.24","Dest":"225.26.231.27"}]"
 
JANSSON API used: jansson_get("origin", "$avp(result1)", "$var(origin)");
 
Any suggestions will be really helpful.are there any error messages?

 Cheers,
 Daniel

-- Daniel-Constantin Mierla [ www.twitter.com/miconda ]( http://www.twitter.com/miconda ) -- [ www.linkedin.com/in/miconda ]( http://www.linkedin.com/in/miconda ) Kamailio Advanced Training - May 22-24 (USA) - [ www.asipto.com ]( http://www.asipto.com ) Kamailio World Conference - May 8-10, 2017 - [ www.kamailioworld.com ]( http://www.kamailioworld.com )

-- Daniel-Constantin Mierla[ www.twitter.com/miconda ]( http://www.twitter.com/miconda ) -- [ www.linkedin.com/in/miconda ]( http://www.linkedin.com/in/miconda )Kamailio Advanced Training - May 22-24 (USA) - [ www.asipto.com ]( http://www.asipto.com )Kamailio World Conference - May 8-10, 2017 - [ www.kamailioworld.com ]( http://www.kamailioworld.com )
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.kamailio.org/pipermail/sr-users/attachments/20170427/090c62b4/attachment.html>


More information about the sr-users mailing list