title: How would I loop through a json file?
body: <p>I'm making a verification system where people link their accounts on two different platforms. I've got the code working, but now I need to check if the code is valid. I'm using .forEach on the json file, yet I keep getting the error:</p>
  <p>client.verificationCodes.forEach is not a function</p>
  <p>and it crashes.</p>
  <p>Here is what the json file looks like:</p>
  <p><a href="https://i.stack.imgur.com/wmyNw.png" rel="nofollow noreferrer">my json file</a></p>
  <p>Here is my code:</p>
  <pre class="lang-js prettyprint-override"><code>const Discord = require('discord.js')
  const rbx = require('noblox.js')
  const fs = require(&quot;fs&quot;)
  const express = require(&quot;express&quot;)
  const app = express()
  app.use(express.json())
  
  const client = new Discord.Client()
  client.verificationCodes = require(&quot;./codes.json&quot;)
  
  require(&quot;dotenv&quot;).config()
  const port = process.env.PORT
  const serverKey = process.env.SERVER_KEY
  const cookie = process.env.COOKIE
  
  function randomString(length, chars) {
      var result = '';
      for (var i = length; i &gt; 0; --i) result += chars[Math.floor(Math.random() * chars.length)];
      return result;
  }
  
  client.on(&quot;ready&quot;, () =&gt; {
      console.log(&quot;Client is ready.&quot;)
  })
  
  app.post(&quot;/getVerificationCode&quot;, function(req,res,next) {
      console.log(&quot;Recieved&quot;)
      if (req.body.serverKey !== serverKey) {
          console.log(&quot;Invalid serverKey supplied.&quot;)
          
          return res.status(403).json({
              error: &quot;You do not have permission to use this.&quot;
          })
      }
  
      let verificationCode = randomString(4,'0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ').toUpperCase()
      const userID = parseInt(req.body.userid)
      console.log(verificationCode)
  
      client.verificationCodes[userID] = {
          code: verificationCode
      }
  
      fs.writeFile(&quot;./codes.json&quot;, JSON.stringify(client.verificationCodes,null,4), err =&gt; {
          if (err) throw err
      })
  
      return res.status(200).json({
          VerificationCode: verificationCode
      })
  })
  
  app.get(&quot;/*&quot;, function(req,res,next) {
      return res.status(200).json({})
  })
  
  client.on(&quot;message&quot;, (message) =&gt; {
      if (message.content.toLowerCase().startsWith(&quot;!verify&quot;)) {
        let args = message.content.split(&quot; &quot;)
        if (!args[1]) {
          message.reply(&quot;You must specify a code.&quot;)
          return
        }
        client.verificationCodes.forEach(vCode =&gt; {
            if (vCode.Code === args[1]) {
                let username = rbx.getUsernameFromId(vCode)
                message.member.setNickname(username)
            }
        })
      }
    })
  
  app.listen(port)
  console.log(`App listening on port ${port}`)
  
  function rbxLogin(newCookie) {
  
      try {
          rbx.setCookie(newCookie)
      } catch(err) {
          console.log(`Invalid cookie supplied, or expired. ${err}`)
      }
  
  
  }
  
  // rbxLogin(cookie)
  
  
  
  client.login(process.env.BOT_TOKEN)
  </code></pre>
  <p>I appreciate help!</p>