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.
-
1Possible duplicate: stackoverflow.com/questions/36856232/…, stackoverflow.com/questions/44474487/…crackmigg– crackmigg2017-10-30 09:38:38 +00:00Commented Oct 30, 2017 at 9: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– Salketer2017-10-30 09:38:39 +00:00Commented Oct 30, 2017 at 9: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– Gowtham2017-10-30 09:54:45 +00:00Commented Oct 30, 2017 at 9:54
Add a comment
|
1 Answer
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!");
});
1 Comment
Gowtham
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.
