create a feeder from a json response

I did try to use the jsonUrl class but the call for this is authenticated and using https, which caused jsonUrl to throw an error so…

I have a json call that returns a list of people like so:

{
“list”: [{
“name”: “Simpson, Bart”,
“personid”: 100121000027,
“room”: 100027
}, {
“name”: “Flintstone, Fred”,
“personid”: 100121000026,
“room”: 100027
}, {
“name”: “Wayne, Bruce”,
“personid”: 100121000020,
“room”: 100027
}]
}

I thought it would be easy to just create a feeder from this return but at runtime I would get an empty feeder error, it seems that the exec which grabbed the data for the feeder ran after the block looking for the feeder.

val persons = new ListBufferMap[String,Any]

exec(http(“Person List”
).post("/person/getList.json")
.headers(headers_json)
.check(status.in(200, 302),
jsonPath("$.list[*]").ofType[Map[String, Any]].findAll.saveAs(“pList”)))
.foreach("${pList}", “person”) {
exec(session => {
val personMap = session(“person”).as[Map[String, Any]]
val personId = personMap(“person_pk”)
persons.append(patientMap)
})
}

// get person details
feed(persons.toArray)
.exec(http(“Person Details”
).get("""/persondetails.json?personId="${personId}""")
.headers(headers_json)
.check(status.in(200, 302)))

So, that too failed. Now I am starting to wonder if I am doing this all wrong. I was hoping to be able to reuse the feeder to drive several more requests that are based on the same id. Is there a way to create a feeder out of a prior request? Is there another way I should be doing this? It seems like it should be a simple thing but it escapes me…

-Gary

Has no one done anything like this before? Seems like it would a common thing to have to do. Any help would be most welcome.

Thanks!
-Gary

There used to be a long standing feature request for supporting authentication on jsonUrl feeder.
I closed it as no one seemed to care. If you really need it, it would be a great opportunity to contribute.

Then, note that, as is, jsonUrl wouldn’t be able to parse your payload.
I don’t get why you need this root list object while you could directly return an array (and that’s what jsonUrl expects).
Why not this instead?

[{

“name”: “Simpson, Bart”,
“personid”: 100121000027,
“room”: 100027
}, {
“name”: “Flintstone, Fred”,
“personid”: 100121000026,
“room”: 100027
}, {
“name”: “Wayne, Bruce”,
“personid”: 100121000020,
“room”: 100027
}]

I am not at liberty to change the API of the web app. I have just been asked to benchmark the performance and stability among other things. Why they have a root list object is beyond me.

The payload that I am after above is returned via an ajax call, which takes a number of parameters. I simplified the psuedo code to make it easier to see what I am doing. Even if I could change the format of the payload I still need to be able to call the method with parameters.

Is there anyway to take the json payload of an ajax call and create a feeder out of it? Seems like it is something that would be very useful and for all I know it already exists, I just cannot figure out how to get it to work.

Thanks!
-Gary

1 Like

Hi Gary,
you can try something like below (if i understood your task correctly):

`
val scn = scenario(“Gary”)
.exec(http(“Get”)
.get("/my_path_to_your_JSON")
.check(jsonPath("$…personid").findAll.saveAs(“IdList”))
)

.foreach("${IdList}", “id”) {
exec(http(“GetID”)
.get("/${id}"))
}
`