Hi Team,
I have a requirement where I have to capture all the values of a key from a json file. Below is the json file data, in which I have to capture “pageLoc” values.
How can we extract multiple values of a key from a json file.
Please help in addressing this.
{
“id”:485,
“productLine”:"",
“documentRenders”:[{
“id”:,
“queueRetryCount”:0,
“processStartTime”:“2021-04-06T10:47:57.000+00:00”,
“pageRenders”:[{
“id”:95183221,
"pageLoc":“httP://www.test.com”,
“pageNumber”:2,
“failureReason”:“null”
},{
“id”:220,
"pageLoc":“httP://www.test.com”,
“pageNumber”:1,
“failureReason”:“null”
}],
“manufacturingTemplate”:“null”
}]
}
Thanks & Regards,
SrinivasM
Hi,
This question is not on gatling subject and does not belong to this mailing list.
Try searching a library to parse json in JVM world. (not only scala but java as well)
Cheers!
What do you mean exactly by “file”?
An entry on the filesystem, or the body of an HTTP response?
Hi Sebastien,
Thank you. Actually I am working on gatling, came across this scenario. In one of the case we could able to get data from Json as below.
val name: JsValue = json \ "user" \ "name"
With this we could able to get one value, but not all the values of that key.
Thanks & Regards,
Srinivas
Hi Stephane,
file - .json file as input from /src/data
Note: from HTTP response I could able to get values with jsonpath, but from file how do we get the values of a key.
Thanks & Regards,
SrinivasM
Then Sébastien’s answer is correct.
This is not a question about Gatling, hence not something we can help with.
This is a generic programming question about parsing a JSON file in Scala or Java.
The line of code you shared seems to be using play-json. I recommend you have a look at their tutorials.
Otherwise, you could use Jackson and parse your file in Java. Again, you can find plenty of resources out there.