var proj = {
Name : "abc",
Roll no : 123
};
How can I write proj data in JSON format in .json file in javascript?
You can save the json object in file.json file like this.
const FileSystem = require("fs");
FileSystem.writeFile('file.json', JSON.stringify(proj), (error) => {
if (error) throw error;
});
(err) => { if (err) throw err; }JSON.stringify (introduced in ES 5.1) will convert the object into a string of JSON.
var json = JSON.stringify(proj);
JavaScript has no built-in mechanism for writing to a file. You generally need something non-standard provided by the host environment. For example, Node.js has the writeFile method of the File System module.
JSON.stringify(proj)to convert it from Javascript to JSON. It would be worth going through a JSON basics course to teach yourself how to create JSON from scratch though, this is a very basic question.