A Simple Method for reading and writing json files by nodejs (mandatory), nodejsjson
Nodejs reads json files
Var fs = reauire ('fs'); var file = "d: \ 0. json "; var result = JSON. parse (fs. readFileSync (file); // operation object
Nodejs writes a json File
Var coors ={}; coors. left_top ={}; coors. right_top ={}; coors. left_bottom ={}; coors. right_bottom ={}; // fill the content var filename = "d :\\ coors \ 0 in coors. json "; fs. writeFileSync (filename, JSON. stringify (coors); // object nested var fs = require ('fs'); var fileDirectory = "D: \ column"; var newfileDirectory = "d: \ new "; if (fs. existsSync (fileDirectory) {var files = fs. readdirSync (fileDirectory); for (var I = 0; I < Files. length; I ++) {var filePath = fileDirectory + "/" + files [I]; var newfilepath = newfileDirectory + "/" + files [I] var filestr = JSON. parse (fs. readFileSync (filePath); for (var item in filestr) {var inter = filestr [item]; for (var m in inter) {inter [m] = parseFloat (inter [m]);} fs. writeFileSync (newfilepath, JSON. stringify (filestr) ;}} else {console. log (fileDirectory + "Not Found! ");}
The above Simple Method for reading and writing json files by nodejs (mandatory) is all the content shared by Alibaba Cloud xiaobian. I hope you can give us a reference and support for our guests.