Parsing JSON files and running code on them

So I have 3 files from my Spotify data that I downloaded. They each have about 10,000 entries in them. I’ve been trying to go through them and grab certain values from each entry. I’ve created a couple programs like the following:

// Parse file - Default for any loop
let x = document.body.innerText
dta = JSON.parse(x)

// Miliseconds played:
cmplt = 0
for(var i = 0; i < dta.length; i++) {
    cmplt += dta[i].msPlayed
}

What I would like to do is put all of this in a script.js file to run it, but I’m not sure how. I’ve been running it on the built-in console so far, and it’s not very efficient. Does anyone know how to link multiple json files to a JS script file?

Here’s a sample of the file:

[
  {
    "endTime" : "2019-06-30 02:50",
    "artistName" : "Flo Rida",
    "trackName" : "Right Round",
    "msPlayed" : 204640
  },
  {
    "endTime" : "2019-06-30 10:58",
    "artistName" : "NF",
    "trackName" : "The Search",
    "msPlayed" : 248040
  },
  {
    "endTime" : "2019-06-30 11:02",
    "artistName" : "NF",
    "trackName" : "When I Grow Up",
    "msPlayed" : 196800
  },
  {
    "endTime" : "2019-06-30 11:07",
    "artistName" : "NF",
    "trackName" : "Therapy Session",
    "msPlayed" : 331480
  },
  {
    "endTime" : "2019-06-30 11:08",
    "artistName" : "Flo Rida",
    "trackName" : "Right Round",
    "msPlayed" : 162
  },
  {
    "endTime" : "2019-06-30 11:08",
    "artistName" : "NF",
    "trackName" : "When I Grow Up",
    "msPlayed" : 203
  }
]

file io?

const fs = require('fs').promises

fs.readFile('stuff.json', 'utf8')
  .then(JSON.parse)
  .then(tracks => tracks.reduce((total, track) => total + track.msPlayed, 0))
  .then(console.log)
  .catch(console.log)

or if you prefer:

const fs = require('fs').promises

async function main () {
  let text
  try {
    text = await fs.readFile('stuff.json', 'utf8')
  } catch (e) {
    console.log(e)
    process.exit(1)
  }
  const tracks = JSON.parse(text)
  const time = tracks.reduce((total, track) => total + track.msPlayed, 0)
  console.log(time)
}

main()

https://nodejs.org/api/fs.html