Answers for "node parse file to json"

4

read json file nodejs

const fs = require('fs');
const path = require('path');

let rawdata = fs.readFileSync(path.resolve(__dirname, 'student.json'));
let student = JSON.parse(rawdata);
console.log(student);
Posted by: Guest on April-13-2020
0

how to load and parse the json data in node js

const data = '{ "name": "Flavio", "age": 35 }'
try {
  const user = JSON.parse(data)
} catch(err) {
  console.error(err)
}
Posted by: Guest on August-10-2021

Code answers related to "Javascript"

Browse Popular Code Answers by Language