Does not make some sense push notification

Who can take a look at my code, I’m trying to get a data inside an object, but it’s impossible. and it does not make any sense, I’m seeing the object ethereum and inside the ethereum object I have a variable called balance, but I can not get into it at all

config.ts

 console.log('----------balance------------');
      console.log( notification.additionalData.ethereum.balance);
      console.log('---------ethereum-------------');   
      console.log(notification.additionalData.ethereum);
      console.log('----------DATA------------');  
      console.log(notification.additionalData);
      console.log('----------notificaiton------------'); 
      console.log(notification);

Postman

`

"to" : "fHyGOQ1ugro:APA91bFz8xqgpL-9M9B5fQxqOcUJEQ0ZjsM2DVSbeXbiif8DDSGokKXipXhC2SoF7Mzim-A6bqB-S8lxr03W3tbNswdytP01Xdm4W_wBuJooS-dTo71bOqXlsq-nzaBp1EZt3GaVFFpa0M-DEAyuWqbRH-7RVX9_dJ4Tw",
 "notification" : {
 "title" : "tittle",
  "sound" : "default",

 "body" : "test"
 },
  "data" : {
     "ethereum" :{
        "balance": "122"
     }

  }
}`

console.log

 2018-07-18 09:56:42.685056-0300 xxx[7771:905653] ----------balance------------
            2018-07-18 09:56:42.685416-0300 xxx[7771:905653] 
            2018-07-18 09:56:42.685773-0300 xxx[7771:905653] ---------ethereum-------------
            2018-07-18 09:56:42.686064-0300 xxx[7771:905653] {"balance":"122"}
            2018-07-18 09:56:42.686382-0300 xxx[7771:905653] ----------DATA------------
            2018-07-18 09:56:42.686638-0300 xxx[7771:905653] {"foreground":true,"ethereum":"{\"balance\":\"122\"}"
,"google.c.a.e":"1","coldstart":false,"gcm.message_id":"0:1531918599095597%9e967f149e967f14"}
            2018-07-18 09:56:42.686851-0300 xxx[7771:905653] ----------notification------------
            2018-07-18 09:56:42.693844-0300 xxx[7771:905653]
     {"additionalData":{"foreground":true,"ethereum":"{\"balance\":\"122\"}","google.c.a.e":"1","coldstart":false,"gcm.message_id":"0:1531918599095597%9e967f149e967f14"},"message":"xxx","title":"tittle","sound":"default"}

The value of ethereum is a string (a JSON stringified to be more specific) and not an object.

You can see that in the log of additionalData:

{"foreground":true,"ethereum":"{\"balance\":\"122\"}"
,"google.c.a.e":"1","coldstart":false,"gcm.message_id":"0:1531918599095597%9e967f149e967f14"}

It should be

{"foreground":true,"ethereum":{"balance":"122"}, "google.c.a.e":"1","coldstart":false,"gcm.message_id":"0:1531918599095597%9e967f149e967f14"}

Or something in those lines. So you could (if possible) change the way the data is being sent in the backend so that the ethereum property receives a json object, not a json stringified.

Or

You can parse the json string in your code:

console.log('----------balance------------');
console.log(JSON.parse(notification.additionalData.ethereum).balance);

So that you get the object, like in:

let ethereumStr: string = notification.additionalData.ethereum; // get the string
let ethereum: { balance: string } = JSON.parse(ethereumStr); // get the object from the string