From notifications@github.com Wed Jun 28 15:39:21 2017 From: Sebastian Damm To: sr-dev@lists.kamailio.org Subject: [sr-dev] [kamailio/kamailio] jansson: can't extract values from string-only json array (#1171) Date: Wed, 28 Jun 2017 06:39:11 -0700 Message-ID: MIME-Version: 1.0 Content-Type: multipart/mixed; boundary="===============1733523936==" --===============1733523936== Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable ### Description I have a json string stored in a variable, and I want to iterate over the val= ues in it. This works if there are integer values in the json string. But if = it consists only of string values, jansson_get throws an error. According to jsonlint, all my json strings are valid. ### Troubleshooting #### Reproduction This is the part of kamailio.cfg leading to the error: ``` # Integer json array $var(myIntList) =3D '[2,3,4,5]'; xlog("L_INFO", "Integer json string is >>>> $var(myIntList) <<<<"); jansson_get('[0]', $var(myIntList), "$var(intValue)"); xlog("L_INFO", "First Int Element: >> $var(intValue) <<"); jansson_get('[1]', $var(myIntList), "$var(intValue)"); xlog("L_INFO", "Second Int Element: >> $var(intValue) <<"); # String json array $var(myStringList) =3D '["foo", "bar", "baz"]'; xlog("L_INFO", "String json string is >>>> $var(myStringList) <<<<"); jansson_get('[0]', $var(myStrList), "$var(strValue)"); xlog("L_INFO", "First Str Element: >> $var(strValue) <<"); jansson_get('[1]', $var(myStrList), "$var(strValue)"); xlog("L_INFO", "Second Str Element: >> $var(strValue) <<"); # Mixed json array $var(myMixedList) =3D '[2, "bar"]'; xlog("L_INFO", "Mixed json string (int first) is >>>> $var(myMixedList) <<<<= "); jansson_get('[0]', $var(myMixedList), "$var(mixedValue)"); xlog("L_INFO", "First Mixed Element: >> $var(mixedValue) <<"); jansson_get('[1]', $var(myMixedList), "$var(mixedValue)"); xlog("L_INFO", "Second Mixed Element: >> $var(mixedValue) <<"); $var(myMixedList) =3D '["bar", 2]'; xlog("L_INFO", "Mixed json string (string first) is >>>> $var(myMixedList) <= <<<"); jansson_get('[0]', $var(myMixedList), "$var(mixedValue)"); xlog("L_INFO", "First Mixed Element: >> $var(mixedValue) <<"); jansson_get('[1]', $var(myMixedList), "$var(mixedValue)"); xlog("L_INFO", "Second Mixed Element: >> $var(mixedValue) <<"); ``` #### Log Messages This is the output generated by the above kamailio.cfg snippet. ``` Jun 28 15:31:12 busch /usr/sbin/kamailio[29961]: INFO: