Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

jansson_get not work when the key contain dot [.] charater #3658

Closed
Jakihiko opened this issue Nov 27, 2023 · 2 comments
Closed

jansson_get not work when the key contain dot [.] charater #3658

Jakihiko opened this issue Nov 27, 2023 · 2 comments

Comments

@Jakihiko
Copy link

Hi,
I have sample json data as below:
$var(mapjson) = {"1.1.1.1": "cloudflare", "2.2.2.2": "ANY"};

I add this line to kamailio script but it does NOT work,

jansson_get("1.1.1.1", "$var(mapjson) ", “$var(domain)“);
or
jansson_get("1.1.1.1", "$var(mapjson) ", “$var(domain)“);

Seem kamailio thinks it is a path not a single key?

Thanks

@miconda
Copy link
Member

miconda commented Nov 28, 2023

Indeed, as I looked at the code, jansson_get() treats the first parameter as json-path and . is a delimiter there.

With the stable kamailio versions at this moment, up to 5.7.x, you can use json module which should work with field name, no json-path.

Alternatively, you can use the an embedded scripting language to parse the json, for example app_jsdt module is offering embedded javascript without any external dependency and inside it you can use JS function JSON.parse(), then walk through the structure and set the value of the desired field to a kamailio.cfg variable.

For the future major stable releases (or if you want to use git master branch now), I pushed some commits to jansson module to change the function jansson_get_field() to work only with the field name, leaving jansson_get() to work with json-path.

I am closing this issue as there are options for stable releases and the development branch got new code for it in the jansson module.

@miconda miconda closed this as completed Nov 28, 2023
@Jakihiko
Copy link
Author

Jakihiko commented Nov 30, 2023

Thanks so much for answer.

For the future major stable releases (or if you want to use git master branch now), I pushed some commits to jansson module to change the function jansson_get_field() to work only with the field name, leaving jansson_get() to work with json-path.

for me it is a perfect solution!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants