Have a problem with JSON

Hello guys! I’m new in JS, have a problem with my code:

tbotping();

function tbotping () {
  var MikroNode = require('mikronode');

  var device = new MikroNode('IP');
  
  //device.setDebug(MikroNode.DEBUG);

  device.connect()
    .then(([login])=>login('username','password'))
    .then(function(conn) {
  
  conn.closeOnDone(true);
  
  var ping = conn.openChannel();
  ping.closeOnDone(true);
  console.log('Get ping');
  ping.write('/ping',{'address':'77.88.8.8','count':'3'});

  ping.data
  .subscribe(function (data) {
  var myJSON = JSON.stringify(data);
  console.log(myJSON);

    });
  });
};

code work correctly, but i can’t understand, how can i get data from myJSON to some variable, for return from main function to use. Now a can only see json data in console. Plz help! Thx alot!

I’ve edited your post for readability. When you enter a code block into a forum post, please precede it with a separate line of three backticks and follow it with a separate line of three backticks to make it easier to read.

You can also use the “preformatted text” tool in the editor (</>) to add backticks around text.

See this post to find the backtick on your keyboard.
Note: Backticks (`) are not single quotes (’).

Hi.
What’s type of data?
If it is a string of JSON, you can parse the data. for example:

const myJSON = JSON.parse(data);
console.log(myJSON);

If not, explain more.

1 Like