I need to create a JSON file in the below format in nodeJS also i need to traverse into the particular position and add the values if any. I have done it in Java, but no idea in NodeJs. It will be helpful if someone helps me. Thanks.
Asked
Active
Viewed 263 times
0
-
1Possible duplicate: https://stackoverflow.com/questions/36856232/write-add-data-in-json-file-using-node-js, https://stackoverflow.com/questions/44474487/read-transform-write-json-file-using-node-js – crackmigg Oct 30 '17 at 09:38
-
This question is unclear. Please, what do you mean by particular position and add values? Where is the JSON coming from? Are you starting from scratch? – Salketer Oct 30 '17 at 09:38
-
Thanks for the reply. I am new to JavaScript and nodeJS. Using PROTRACTOR i am automating Angular application. So once execution completed, i will create a Json file for reporting. I need to create a JSON file from nodeJS on every execution, for example : Inside testcases, for the first execution i will create some set of data, for the second execution i will traverse into the same testcases and will append with another set of data. – Gowtham Oct 30 '17 at 09:54
1 Answers
0
If my understanding is correct, you are using Protractor to automate AngularJS tests and write the results as JSON for reporting / for parsing it back once done? If that's the case, you could simply store the results as a Object in Javascript and write it out using fs node package.
Writing the JSON Report file
var fs = require('fs');
//..Protractor .. and other logic..
var results = { Project : "xxx" , ....};
//...more of that assignment....
//You could use JSON.parse() or JSON.stringify() to read/convert this object to string vice versa and fs package to read/write it to file.
fs.writeFile("/tmp/testreport.json", JSON.stringify(results), function(err) {
if(err) {
return console.log(err);
}
console.log("The test report file was saved as JSON file!");
});

hem
- 1,012
- 6
- 11
-
Thanks for your time. I hope it will be helpful, I will try and get back to you incase if i face any issues. Thanks once again. – Gowtham Oct 31 '17 at 02:12