0

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.

JSON file format

3
  • 1
    Possible duplicate: stackoverflow.com/questions/36856232/…, stackoverflow.com/questions/44474487/… Commented 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? Commented 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. Commented Oct 30, 2017 at 9:54

1 Answer 1

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!");
}); 
Sign up to request clarification or add additional context in comments.

1 Comment

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.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.