<!-- Kamailio Project uses GitHub Issues only for bugs in the code or feature requests.
If you have questions about using Kamailio or related to its configuration file, ask on sr-users mailing list:
* http://lists.sip-router.org/cgi-bin/mailman/listinfo/sr-users
If you have questions about developing extensions to Kamailio or its existing C code, ask on sr-dev mailing list
* http://lists.sip-router.org/cgi-bin/mailman/listinfo/sr-dev
Please try to fill this template as much as possible for any issue. It helps the developers to troubleshoot the issue.
If you submit a feature request (or enhancement), you can delete the text of the template and only add the description of what you would like to be added.
If there is no content to be filled in a section, the entire section can be removed.
You can delete the comments from the template sections when filling.
You can delete next line and everything above before submitting (it is a comment). -->
### Description
<!-- Explain what you did, what you expected to happen, and what actually happened. -->
### Troubleshooting
#### Reproduction
Hello, i have an issue with the JSON module .
i have JSON response from a HTTP request to process in my script:
{"status":"SUCCESS"}
i use the command HTTP_query:
_http_query("http://xxxxx", "$var(result)");_
then i try to parse my result:
_json_get_field("$var(result)", "status", "$var(status)");_ But when i log my result: _xlog("L_INFO", "$var(status)");_
i have a wrong output:
_INFO: <script>: "SUCCESS"_
double quote is embedded in the string variable which is wrong because this not part of my json value.
Is there any way to fix this behaviour or having a new function in order to retrieve the right value of my json field?
Thank you for your help.
Hi Thomas,
I faced the same issue. looks like some bug with json module.
jansson_get_field(*"$var(result)", "status", "$var(status)");*
worked for me. It resulted as expected *INFO: <script>: SUCCESS*
-- regards,
abdul basit | p: +92 32 1416 4196 | o: +92 30 0841 1445
On 21 February 2018 at 20:41, Thomas Carvello notifications@github.com wrote:
Description Troubleshooting Reproduction
Hello, i have an issue with the JSON module .
i have JSON response from a HTTP request to process in my script:
{"status":"SUCCESS"}
i use the command HTTP_query:
*http_query("http://xxxxx http://xxxxx", "$var(result)");*
then i try to parse my result:
*json_get_field("$var(result)", "status", "$var(status)");*
But when i log my result: *xlog("L_INFO", "$var(status)");*
i have a wrong output:
*INFO: <script>: "SUCCESS"*
double quote is embedded in the string variable which is wrong because this not part of my json value.
Is there any way to fix this behaviour or having a new function in order to retrieve the right value of my json field?
Thank you for your help.
— You are receiving this because you are subscribed to this thread. Reply to this email directly, view it on GitHub https://github.com/kamailio/kamailio/issues/1452, or mute the thread https://github.com/notifications/unsubscribe-auth/AF36ZTQBSiU8c6rfeldJdX5ER-bV8dZOks5tXDkmgaJpZM4SN2bQ .
Kamailio (SER) - Development Mailing List sr-dev@lists.kamailio.org https://lists.kamailio.org/cgi-bin/mailman/listinfo/sr-dev
I checked the code and json_get_field() formats the result in a JSON value, making strings to be enclosed in the quotes. This is to support cases when the value of requested key is a structure, so practically the result in this case will be a JSON serialization of the structure. I just added a note to clarify this in the docs of the module.
I think this is ok over all. Maybe there should be added some helper functions to get string or int values, like json_get_string() and json_get_int().
Otherwise, jansson module is supposed to be like ng version of the json module, with more features (e.g., json-path support).
I am closing this one because it is how the module was coded. I will try to add the helper functions when I get a chance, or maybe someone else does it meanwhile ... @eschmidbauer did some work lately with the json module, maybe he can jump in here ...
Closed #1452.
not an ideal solution but this is how i address the problem: ``` json_get_field("$var(result)", "status", "$var(status)"); $var(status) = $(var(status){s.strip,1}); #strip quotes $var(status) = $(var(status){s.striptail,1}); #strip quotes ```