The following code works in Node.js v14.16.0. However, I can't find any documentation indicating that JSON.parse() accepts a Buffer as the argument. Is this expected behavior—yet not documented—or perhaps I'm doing something wrong?
const fs = require('fs');
const dataPayload = fs.readFileSync('data.json'); // a buffer
const data = JSON.parse(dataPayload);
console.log(data); // { name: 'Jane', age: 24 } -> an object
Contents of data.json:
{
"name": "Jane",
"age": 24
}
The spec does not mention anything related to this.