Updating entries in a json file

The name of the pictureThe name of the pictureThe name of the pictureClash Royale CLAN TAG#URR8PPP





.everyoneloves__top-leaderboard:empty,.everyoneloves__mid-leaderboard:empty margin-bottom:0;







up vote
1
down vote

favorite












I have the following Data.json file and I would like to update some of the values.




"A0_Water":"-306.3",
"A1_Water":"0.0",
"A2_Water":"0.0",
"A3_Water":"0.0",
"Barometer":"100.8",
"Bar_Offset":"0",
"Temp":"29.95",
"ip":"192.168.2.47",
"serial":"02:42:52:bf:82:27",
"A0_Sensor":"PS30A",
"A1_Sensor":"None",
"A2_Sensor":"None",
"A3_Sensor":"None",
"A0_Offset":"0",
"A1_Offset":"0",
"A2_Offset":"0",
"A3_Offset":"0"



I am new to coding so any help will be much appriciated.
This is the code that I have working: The var data object that I created contains the entries that I want to update in the Data.json file but I was not sure how to use it. The remainder of the code is what I was able to get working but I am sure there is a better way to update the entries in the Data.json file



var data = 
'A0_Water': c_inh2o_A0,
'A1_Water': c_inh2o_A1,
'A2_Water': c_inh2o_A2,
'A3_Water': c_inh2o_A3,
'Barometer': b_mbar_corrected,
'Temp': b_temp
;

var fileName = '/home/admin/reactwatertracker/src/var/Data.json';
var file4 = require(fileName);
var file5 = file4;
var file6 = file4;
var file7 = file4;
var file8 = file4;
var file9 = file4;

file4['A0_Water'] = c_inh2o_A0;
file5['A1_Water'] = c_inh2o_A1;
file6['A2_Water'] = c_inh2o_A2;
file7['A3_Water'] = c_inh2o_A3;
file8['Temp'] = b_temp;
file9['Barometer'] = b_mbar_corrected;

console.log('Writing to' + fileName);
fs.writeFile(fileName, JSON.stringify(file4,file5,file6,file7,file8,file9, null, 2), function (err)
if (err) return console.log(err);
console.log (JSON.stringify(file4));


);







share|improve this question

























    up vote
    1
    down vote

    favorite












    I have the following Data.json file and I would like to update some of the values.




    "A0_Water":"-306.3",
    "A1_Water":"0.0",
    "A2_Water":"0.0",
    "A3_Water":"0.0",
    "Barometer":"100.8",
    "Bar_Offset":"0",
    "Temp":"29.95",
    "ip":"192.168.2.47",
    "serial":"02:42:52:bf:82:27",
    "A0_Sensor":"PS30A",
    "A1_Sensor":"None",
    "A2_Sensor":"None",
    "A3_Sensor":"None",
    "A0_Offset":"0",
    "A1_Offset":"0",
    "A2_Offset":"0",
    "A3_Offset":"0"



    I am new to coding so any help will be much appriciated.
    This is the code that I have working: The var data object that I created contains the entries that I want to update in the Data.json file but I was not sure how to use it. The remainder of the code is what I was able to get working but I am sure there is a better way to update the entries in the Data.json file



    var data = 
    'A0_Water': c_inh2o_A0,
    'A1_Water': c_inh2o_A1,
    'A2_Water': c_inh2o_A2,
    'A3_Water': c_inh2o_A3,
    'Barometer': b_mbar_corrected,
    'Temp': b_temp
    ;

    var fileName = '/home/admin/reactwatertracker/src/var/Data.json';
    var file4 = require(fileName);
    var file5 = file4;
    var file6 = file4;
    var file7 = file4;
    var file8 = file4;
    var file9 = file4;

    file4['A0_Water'] = c_inh2o_A0;
    file5['A1_Water'] = c_inh2o_A1;
    file6['A2_Water'] = c_inh2o_A2;
    file7['A3_Water'] = c_inh2o_A3;
    file8['Temp'] = b_temp;
    file9['Barometer'] = b_mbar_corrected;

    console.log('Writing to' + fileName);
    fs.writeFile(fileName, JSON.stringify(file4,file5,file6,file7,file8,file9, null, 2), function (err)
    if (err) return console.log(err);
    console.log (JSON.stringify(file4));


    );







    share|improve this question





















      up vote
      1
      down vote

      favorite









      up vote
      1
      down vote

      favorite











      I have the following Data.json file and I would like to update some of the values.




      "A0_Water":"-306.3",
      "A1_Water":"0.0",
      "A2_Water":"0.0",
      "A3_Water":"0.0",
      "Barometer":"100.8",
      "Bar_Offset":"0",
      "Temp":"29.95",
      "ip":"192.168.2.47",
      "serial":"02:42:52:bf:82:27",
      "A0_Sensor":"PS30A",
      "A1_Sensor":"None",
      "A2_Sensor":"None",
      "A3_Sensor":"None",
      "A0_Offset":"0",
      "A1_Offset":"0",
      "A2_Offset":"0",
      "A3_Offset":"0"



      I am new to coding so any help will be much appriciated.
      This is the code that I have working: The var data object that I created contains the entries that I want to update in the Data.json file but I was not sure how to use it. The remainder of the code is what I was able to get working but I am sure there is a better way to update the entries in the Data.json file



      var data = 
      'A0_Water': c_inh2o_A0,
      'A1_Water': c_inh2o_A1,
      'A2_Water': c_inh2o_A2,
      'A3_Water': c_inh2o_A3,
      'Barometer': b_mbar_corrected,
      'Temp': b_temp
      ;

      var fileName = '/home/admin/reactwatertracker/src/var/Data.json';
      var file4 = require(fileName);
      var file5 = file4;
      var file6 = file4;
      var file7 = file4;
      var file8 = file4;
      var file9 = file4;

      file4['A0_Water'] = c_inh2o_A0;
      file5['A1_Water'] = c_inh2o_A1;
      file6['A2_Water'] = c_inh2o_A2;
      file7['A3_Water'] = c_inh2o_A3;
      file8['Temp'] = b_temp;
      file9['Barometer'] = b_mbar_corrected;

      console.log('Writing to' + fileName);
      fs.writeFile(fileName, JSON.stringify(file4,file5,file6,file7,file8,file9, null, 2), function (err)
      if (err) return console.log(err);
      console.log (JSON.stringify(file4));


      );







      share|improve this question











      I have the following Data.json file and I would like to update some of the values.




      "A0_Water":"-306.3",
      "A1_Water":"0.0",
      "A2_Water":"0.0",
      "A3_Water":"0.0",
      "Barometer":"100.8",
      "Bar_Offset":"0",
      "Temp":"29.95",
      "ip":"192.168.2.47",
      "serial":"02:42:52:bf:82:27",
      "A0_Sensor":"PS30A",
      "A1_Sensor":"None",
      "A2_Sensor":"None",
      "A3_Sensor":"None",
      "A0_Offset":"0",
      "A1_Offset":"0",
      "A2_Offset":"0",
      "A3_Offset":"0"



      I am new to coding so any help will be much appriciated.
      This is the code that I have working: The var data object that I created contains the entries that I want to update in the Data.json file but I was not sure how to use it. The remainder of the code is what I was able to get working but I am sure there is a better way to update the entries in the Data.json file



      var data = 
      'A0_Water': c_inh2o_A0,
      'A1_Water': c_inh2o_A1,
      'A2_Water': c_inh2o_A2,
      'A3_Water': c_inh2o_A3,
      'Barometer': b_mbar_corrected,
      'Temp': b_temp
      ;

      var fileName = '/home/admin/reactwatertracker/src/var/Data.json';
      var file4 = require(fileName);
      var file5 = file4;
      var file6 = file4;
      var file7 = file4;
      var file8 = file4;
      var file9 = file4;

      file4['A0_Water'] = c_inh2o_A0;
      file5['A1_Water'] = c_inh2o_A1;
      file6['A2_Water'] = c_inh2o_A2;
      file7['A3_Water'] = c_inh2o_A3;
      file8['Temp'] = b_temp;
      file9['Barometer'] = b_mbar_corrected;

      console.log('Writing to' + fileName);
      fs.writeFile(fileName, JSON.stringify(file4,file5,file6,file7,file8,file9, null, 2), function (err)
      if (err) return console.log(err);
      console.log (JSON.stringify(file4));


      );









      share|improve this question










      share|improve this question




      share|improve this question









      asked Aug 2 at 12:10









      Dave Murphy

      61




      61

























          active

          oldest

          votes











          Your Answer




          StackExchange.ifUsing("editor", function ()
          return StackExchange.using("mathjaxEditing", function ()
          StackExchange.MarkdownEditor.creationCallbacks.add(function (editor, postfix)
          StackExchange.mathjaxEditing.prepareWmdForMathJax(editor, postfix, [["\$", "\$"]]);
          );
          );
          , "mathjax-editing");

          StackExchange.ifUsing("editor", function ()
          StackExchange.using("externalEditor", function ()
          StackExchange.using("snippets", function ()
          StackExchange.snippets.init();
          );
          );
          , "code-snippets");

          StackExchange.ready(function()
          var channelOptions =
          tags: "".split(" "),
          id: "196"
          ;
          initTagRenderer("".split(" "), "".split(" "), channelOptions);

          StackExchange.using("externalEditor", function()
          // Have to fire editor after snippets, if snippets enabled
          if (StackExchange.settings.snippets.snippetsEnabled)
          StackExchange.using("snippets", function()
          createEditor();
          );

          else
          createEditor();

          );

          function createEditor()
          StackExchange.prepareEditor(
          heartbeatType: 'answer',
          convertImagesToLinks: false,
          noModals: false,
          showLowRepImageUploadWarning: true,
          reputationToPostImages: null,
          bindNavPrevention: true,
          postfix: "",
          onDemand: true,
          discardSelector: ".discard-answer"
          ,immediatelyShowMarkdownHelp:true
          );



          );








           

          draft saved


          draft discarded


















          StackExchange.ready(
          function ()
          StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fcodereview.stackexchange.com%2fquestions%2f200806%2fupdating-entries-in-a-json-file%23new-answer', 'question_page');

          );

          Post as a guest



































          active

          oldest

          votes













          active

          oldest

          votes









          active

          oldest

          votes






          active

          oldest

          votes










           

          draft saved


          draft discarded


























           


          draft saved


          draft discarded














          StackExchange.ready(
          function ()
          StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fcodereview.stackexchange.com%2fquestions%2f200806%2fupdating-entries-in-a-json-file%23new-answer', 'question_page');

          );

          Post as a guest













































































          Popular posts from this blog

          Greedy Best First Search implementation in Rust

          Function to Return a JSON Like Objects Using VBA Collections and Arrays

          C++11 CLH Lock Implementation