Reading data from a shared Array

Hi,

I have one json file in the below format,

{
              "Product1" : [
                               {"model":"xxx","mof":yy},
                                {"model":"xxx", "mof":zz}
                               ]
              "Product2":[
                            {"model":"xxx","mof":yy},
                            {"model":"xxx", "mof":zz}
                        ]

}

In the K6 script, I am using SharedArray to read the above json file.

const data = new SharedArray('products', function(){
return JSON.parse(open('data.json'));
});

Query 1 : I was able to access Product1 details. How can I access Product2 details?

Query 2 : Is there any way to group user actions in the k6 browser script so that we will get browser_req_duration for each transaction ( for e.g. duration for submitting a form , searching for an item etc…) ? I have tried performance.mark method. Is there any other alternative?

Thanks

Hi @betsybenny2000

For me running the script failed on parsing the json file. With the following json file I can access the Product2 with console.log(data[1]);

[
  {"Product1" : [
                   {"model":"xxx","mof":"yy"},
                    {"model":"xxx", "mof":"zz"}
                   ]},
  {"Product2":[
                {"model":"xxx","mof":"yy"},
                {"model":"xxx", "mof":"zz"}
            ]
          }
]
1 Like