9951 explained code solutions for 126 technologies


nodejsHow to convert JSON to Buffer


const json = {name: 'Joe', age: 98};
let buf = Buffer.from(JSON.stringify(json));ctrl + c
{name: 'Joe', age: 98}

sample JSON

Buffer.from

create Buffer from given object (string in our case)

JSON.stringify

convert given object to JSON string