You are reading a single comment by @allObjects and its replies. Click here to read the full conversation.
  • ...with that said - and to come full circle - your initial code is missing only two (2) single quotes in the first line...

    var sensorReadings = '{ "restempvalue" : 0, "phvalue" : 0, "ecvalue" : 0 }';
    var sensorObj = JSON.parse(sensorReadings); // Object from JSON
    function getAllSensorData() {
      /*restemp.takeReading(function(val) {
        console.log(val);
      });
      ph.takeReading(function(val) {
        console.log(val);
      });*/
      ec.takeReading(function(val) {
        sensorObj.restempvalue = val;
        console.log(val);
      });
    }
    

    Note: JSON is always a String (object)... JS Object Notated (as a string). It is the literal representation of an object, like the literal representation of a simple string is always in "DoubleQuotes" or 'SingleQuotes', or like literal number, for example 6, is just the 'naked' number, or like the literal booleans true and false ('naked' symbols / reserved words), or the null and undefined object null and undefined (also 'naked' symbols / reserved words)... versus the variable referencing - or value holder - of an object, string, boolean, number, null and undefined respectively.

About

Avatar for allObjects @allObjects started