From c8fc72dddbe0ad6fde325bc6ee5b407f3446d2be Mon Sep 17 00:00:00 2001 From: Daniel W Date: Sat, 25 Feb 2017 11:19:26 -0500 Subject: [PATCH] convert pub/sub response to valid json when you have multiple messages --- README.markdown | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/README.markdown b/README.markdown index 54ad8758..e5b99fc2 100644 --- a/README.markdown +++ b/README.markdown @@ -309,6 +309,11 @@ function checkData() { chunk = response.slice(previous_response_length); previous_response_length = response.length; console.log(chunk); +//if you get messages faster than you can parse one at a time- convert to valid json first + var replacedChunk = chunk.replace(/}{"SUBSCRIBE":/g, '},{"SUBSCRIBE": '); + var validJSON = '['+replacedChunk+']' + var json = JSON.parse(validJSON); + console.log(json); } };