RabbitMQ and Node.js converting message buffer to JSON

If you are using amqplib then the below code solves the issue.

In the sender.js file i convert data to JSON string

var data = [{
   name: '********',
   company: 'JP Morgan',
   designation: 'Senior Application Engineer'
}];

ch.sendToQueue(q, Buffer.from(JSON.stringify(data)));

And in the receiver.js i use the below code to print the content from the queue. Here i parse the msg.content to JSON format.

ch.consume(q, function(msg) {
   console.log(" [x] Received");
   console.log(JSON.parse(msg.content));
}, {noAck: true});

The answer was right in front of me. Leaving this up in case someone else has the same issue, but the solution was:

console.log(message.data.toString('utf8'));

I was getting the object and trying to convert it all and not the data property.