Jump to content


Photo
Question

How can I modify values in a Json file?

node.js

  • Please log in to reply
1 reply to this topic

#1 Go Fast

Go Fast

    Member

  • Member
  • PipPip
  • 22 posts

Posted 11 March 2018 - 09:54 AM

My Json file looks like this:

{
"TotalItemsTraded": {
"TotalKeys": 0
}
 
}
 
Json is called: 'TotalSold.json'
 
How can I update it's value? I'm trying to add an integer to 'TotalKeys' (Another function is calculating everything and im just trying to update the json file value)


#2 Dr. McKay

Dr. McKay

    Developer

  • Administrator
  • 1,652 posts

Posted 11 March 2018 - 06:19 PM

let sold = JSON.parse(require('fs').readFileSync('TotalSold.json').toString('utf8'));
sold.TotalItemsTraded.TotalKeys += something;
require('fs').writeFileSync('TotalSold.json', JSON.stringify(sold, undefined, "\t"));

  • Go Fast likes this





Also tagged with one or more of these keywords: Question, node.js

0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users