node.js - Parsing a string (gotten from rabbitmq) into JSON -
i using rabbittmq consume json (that got mongodb) in nodejs application. below mentioned code snippet :
ch.consume(q, function(msg){ var clone = msg.content.tostring(); var cloned = json.parse(clone.replace(/_/g,"")); //var cloned = json.parse(clone); console.log(' [x] recieved %s', cloned); // shows correct json var keys = object.keys(cloned); (var = 0; < keys.length; i++) { console.log('keys....', cloned[keys[i]]); } //-----keys coming 1 character per key
if try parse "clone", unexpected error due underscore @ position 0. , not able parse json.
and when replace underscore blank string, not able parse json error comes stating "unexpected token v in json @ position 2".
in order see if parsed correctly displaying keys. keys come
keys.... { keys.... keys.... v keys.... : keys.... keys.... 0 keys.... , keys.... keys.... keys.... keys.... f keys.... o keys.... l keys....
please me here !! in advance !
Comments
Post a Comment