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);
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);
write json file nodejs
const fs = require('fs');
const path = require('path');
let student = {
name: 'Mike',
age: 23,
gender: 'Male',
department: 'English',
car: 'Honda'
};
fs.writeFileSync(path.resolve(__dirname, 'student.json'), JSON.stringify(student));
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)
}
how to read and parse a json file with rapidjson
FILE *fp = fopen("input.json", "r"); // stupid windows need rb
char buf[0XFFFF];
//FileReadStream(FILE *fp, char *buffer, std::size_t bufferSize)
rapidjson::FileReadStream input(fp, buf, sizeof(buf));
rapidjson::Document document;
document.ParseStream(input);
fclose(fp);
cout << document["hello"].GetString() << endl;
Copyright © 2021 Codeinu
Forgot your account's password or having trouble logging into your Account? Don't worry, we'll help you to get back your account. Enter your email address and we'll send you a recovery link to reset your password. If you are experiencing problems resetting your password contact us