[OpenSIPS-Users] Unable to parse JSON

Ben Newlin Ben.Newlin at genesys.com
Mon Aug 5 08:26:28 EDT 2019


Hamid,

If would be helpful if you included the part of your script where you copy the REST response into the JSON variable.

There has already been a response to this suggesting that the issue is likely in how you are setting the $json(response) variable. If you want the variable to parse string input into JSON, you must use assignment with := not =. [1]

[1] https://opensips.org/html/docs/modules/2.4.x/json.html#pv_json

Ben Newlin

From: Users <users-bounces at lists.opensips.org> on behalf of Hamid Hashmi <hamid2kviii at hotmail.com>
Reply-To: OpenSIPS users mailling list <users at lists.opensips.org>
Date: Monday, August 5, 2019 at 2:51 AM
To: "users at lists.opensips.org" <users at lists.opensips.org>
Subject: Re: [OpenSIPS-Users] Unable to parse JSON

Opensips Users,

Waiting for your comments/help/Suggestion.


Regards

Hamid R. Hashmi

________________________________
From: Hamid Hashmi
Sent: Tuesday, July 30, 2019 12:40 PM
To: users at lists.opensips.org <users at lists.opensips.org>
Subject: Unable to parse JSON

Below is the JSON response received in an async rest post request (mod rest_client).

 xlog("L_INFO","[$fU $tU $ci $rm] PUSH Server responded with $var(rcode):$json(response)");

{
  "error": null,
  "payload": {
    "results": [
      {
        "error": {
          "code": "messaging/registration-token-not-registered",
          "message": "The provided registration token is not registered. A previously valid registration token can be unregistered for a variety of reasons. See the error documentation for more details. Remove this registration token and stop using it to send messages."
        }
      }
    ],
    "canonicalRegistrationTokenCount": 0,
    "failureCount": 1,
    "successCount": 0,
    "multicastId": 4814925980047675000
  }
}

But when I try to print the following line

xlog("L_INFO","[$fU $tU $ci $rm] PUSH Server responded with $var(rcode) with Failure Count: $json(response/payload/failureCount)");


it gives me a NULL Value. What am I doing wrong?


version: opensips 2.4.6 (x86_64/linux)
flags: STATS: On, DISABLE_NAGLE, USE_MCAST, SHM_MMAP, PKG_MALLOC, F_MALLOC, FAST_LOCK-ADAPTIVE_WAIT
ADAPTIVE_WAIT_LOOPS=1024, MAX_RECV_BUFFER_SIZE 262144, MAX_LISTEN 16, MAX_URI_SIZE 1024, BUF_SIZE 65535
poll method support: poll, epoll, sigio_rt, select.
git revision: edef893c5
main.c compiled on 11:29:33 Jul 29 2019 with gcc 4.8.5



[root at sip-3 opc]# rpm -qa | grep json
json-c-devel-0.11-4.el7_0.x86_64
libfastjson-0.99.4-3.el7.x86_64
python-jsonpatch-1.2-4.el7.noarch
json-c-0.11-4.el7_0.x86_64
json-glib-devel-1.4.2-2.el7.x86_64
python-jsonpointer-1.9-2.el7.noarch
json-glib-1.4.2-2.el7.x86_64



Regards



Hamid R. Hashmi
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.opensips.org/pipermail/users/attachments/20190805/b9f12f38/attachment-0001.html>


More information about the Users mailing list