I’m not too familiar with JavaScript, but I think you’re getting the error because the escaped quotes (\") are being turned into quotes before parsing. You’ll need to escape the blackslashes:
function testjson () {
var obj = $.parseJSON('{"type":"MESSAGE","data":{"topic":"channel-bitsevents.XXXX","message":"{\\"user_name\\":\\"metal_babble\\",\\"channel_name\\":\\"cleartonic\\",\\"user_id\\":\\"XXXX\\",\\"channel_id\\":\\"XXXX\\",\\"time\\":\\"2016-09-18T13:54:13.668Z\\",\\"chat_message\\":\\"cheer1 Test 2.\\",\\"bits_used\\":1,\\"total_bits_used\\":2,\\"context\\":\\"cheer\\"}"}}');
console.log(obj.type);
// Parse message as JSON
var message = $.parseJSON(obj.data.message);
console.log(message.channel_name);
alert("Success");
}
That code also shows how you parse the message and access it’s properties.
Note that you of course only have to escape the backslashes if you put the PubSub data directly into the code like this (I assume for testing), if you actually receive it over the websocket it wouldn’t be necessary.