node.js - more elegant way to convert Nodejs Buffer of utf8 to json? -


is there more elegant way convert buffer, in nodejs json this?

json.parse(payload.originalevent.metadata.tostring('utf8')) 

if do

payload.originalevent.metadata.tojson() 

i utf8 encoded string.

i feel though may doing work wrapped in buffer method.

---edit awesome, fixed (unrelated) bug while trying data you.

console.log(payload.originalevent.metadata); console.log(payload.originalevent.metadata.tojson()); console.log(payload.originalevent.metadata.tostring('utf8'));   <buffer 7b 22 65 76 65 6e 74 54 79 70 65 4e 61 6d 65 22 3a 22 74 65 73 74 69 6e 67 45 76 65 6e 74 22 7d>  { type: 'buffer',   data: [ 123, 34, 101, 118, 101, 110, 116, 84, 121, 112, 101, 78, 97, 109, 101, 34, 58,34, 116, 101,115, 116,105, 110, 103, 69, 118, 101, 110, 116, 34,125 ] }  {"eventtypename":"testingevent"} 

however, last example, it's string must json.parse in order access property

i hope helps

thanks


Comments

Popular posts from this blog

How to provide Authorization & Authentication using Asp.net, C#? -

toolbar - How to add link to user registration inside toobar in admin joomla 3 custom component -

How to use Authorization & Authentication in Asp.net, C#? -