buf.toJSON()
- Return: <Object>
Returns a JSON representation of the Buffer instance. JSON.stringify()
implicitly calls this function when stringifying a Buffer instance.
Example:
const buf = Buffer.from('test'); const json = JSON.stringify(buf); console.log(json); // Prints: '{"type":"Buffer","data":[116,101,115,116]}' const copy = JSON.parse(json, (key, value) => { return value && value.type === 'Buffer' ? Buffer.from(value.data) : value; }); console.log(copy.toString()); // Prints: 'test'
Please login to continue.