0

I have tried of reading values from excel and convert to JSON and everything perfect. But what I need is I know how my JSON input now should be. But in order to achieve that required JSON, I want to know how to give those values in excel. ? Kindly help me how to specify in excel and then I can able to convert that excel to JSON. I am attaching the expected JSON. so that gives me an idea on how to give excel

How should I give in excel to get this desired JSON?

Kindly help me . Since I tried using NPMSjs site but all the example they are showing was testcase1 should be given as sheet name and testcase2 should be available as sheet 2 etc. But what I want to have is inside that one sheet I want to maintain the two cases. In StackOverflow itself, I searched but what output I am required is not available. for the below output to get in JSON how to give input in excel. Please help me. I have to include and proceed automation

Currently, I am going to start Automation using protractor jasmine framework.

Sample JSON:

{

    "scenario1" : [
                    {"product" :"Car", "code" :"221"},
                    {"product" :"bike", "code" :"456"},
                    {"product" :"scooty", "code" :"456"}               
                ],

    "scenario2" : 

        {"firstName" :"brand", "lastName" :"result","product":"final"}



}
Partha
  • 402
  • 4
  • 15
Jai
  • 1
  • 1

1 Answers1

0

Save the scenario name in first column, input data for scenario in second column.

enter image description here

// implement function readExcel to read excel into array as following:
// [ 
//    ['scenario1', '[{"product'.....]' ]
//    ['scenario2', '{"firstName.....'  ]
// ]
rows = readExcel('file_path', 'sheet_name');

datas = {}; 

// convert array into map
rows.forEach(function(row){
   datas[row[0]] = row[1];
});

// use scenario name to get its data from map
var tmp = JSON.parse(datas['scenario1']);
yong
  • 13,357
  • 1
  • 16
  • 27
  • Thank you so much for your reply . Really needed and gave me new idea . Actually this test suite will be executed by changing data alone who dont have deep understanding. Instead of giving the tag in excel. Any macro or any other concept to convert the data specified in each row to form the tag like you shown. Is der any way to do ? – Jai Jun 07 '18 at 15:17