title: Is this a correct way to parse incoming JSON over websocket, and respond depending on the type of message?
body: <p>So I am receiving JSON over a websocket from a chargepoint using OCPP 1.6 JSON.
  I am trying to parse the message and respond appropriately, depending on what the message is, using Node.js</p>
  
  <p>Here is the message that I recieve:</p>
  
  <pre><code>[ 2,
    'bc7MRxWrWFnfQzepuhKSsevqXEqheQSqMcu3',
    'BootNotification',
    { chargePointVendor: 'AVT-Company',
      chargePointModel: 'AVT-Express',
      chargePointSerialNumber: 'avt.001.13.1',
      chargeBoxSerialNumber: 'avt.001.13.1.01',
      firmwareVersion: '0.9.87',
      iccid: '',
      imsi: '',
      meterType: 'AVT NQC-ACDC',
      meterSerialNumber: 'avt.001.13.1.01' } ]
  </code></pre>
  
  <p>In this case it is the 'BootNotification' message, to which I need to respond with an 'Accepted' message.</p>
  
  <p>Here is my code:</p>
  
  <pre><code>const WebSocket = require('ws');
  
  const wss = new WebSocket.Server({ port: 8080 });
  
  wss.on('connection', function connection(ws) {
    ws.on('message', function incoming(message) {
  
      //Make incoming JSON into javascript object
      var msg = JSON.parse(message)
  
      // Print whole message to console
      console.log(msg)
  
      // Print only message type to console. For example BootNotification, Heartbeat etc...
     console.log("Message type: " + msg[2])
  
      // Send response depending on what the message type is
      if (msg[2] === "BootNotification") {
        //Send correct response
  
      } // Add all the message types
  
    });
  
  
  });
  </code></pre>
  
  <p>With this I get the message type printed to the console as a string:</p>
  
  <pre><code>Message type: BootNotification
  </code></pre>
  
  <p>So my question is that is this the correct way to get the type of the message? 
  I am new to this so I want to make sure.</p>
  
  <p>The specification for OCPP 1.6 JSON is available here: <a href="https://www.openchargealliance.org/downloads/" rel="nofollow noreferrer">OpenChargeAlliance website</a></p>