Filtering JSON Feeder records

Hi, I’m having trouble with a simple use case : filtering a Feeder.
I would like to filter a feeder based on a specific key value.

Exemple with the following json file content :
{ “id”:19434, “type”:“low” },
{ “id”:19435, “type”:“high” },
{ “id”:19435, “type”:“high” }
My goal is to retrieve all elements with the value “high” for the specific key “type”.

val records = jsonFile(“configs/file.json”).readRecords
val recordsByType: Map[String, Seq[Record[Any]]] = records.filter {
client =>
client(“type”).toString == “high”

I’m not used to Scala/Collections methods and obviously the code above does not work. But it tells what I try to achieve :slight_smile:

I’m pretty sure there is something quite simple to do, but I’m not aware of it.


Hello Fabien,

found this doc: Vector Filtering
Try the below:

val recordsByType = records.filter(_(“type”) == “high”)

underscore ‘_’ defines every value and since the values are in Map, we can get a value from Map by mapName(key)
so, we mentioning as _(key) i.e. in our case: _(“type”)

Sujin Sam

The filtering logic is correct, the result type isn’t: should ne Seq[Record[Any]]].

Exact, I also realized the type issue earlier today…

So I got my filtered list. But, now , I would like to create a new circular feeder from it.

val newFeeder = recordsByType.circular

It raises a compilation error since circular is not a member of this new Seq[Record[Any]] list.

Which transformation to recordsByType should I apply so my filtered list can be handled as a Feeder ?

I checked Gatling source code, specifically jsonFile method and tried to do use InMemoryFeederSource constructor but it requires an IndexedSeq instead of a Seq.

Any idea? Again, I’m quite sure there is an easy way -_-


toIndexedSeq helps to convert Seq to IndexedSeq

the below code works for me:

val records = jsonFile(“idFile.json”).readRecords.filter(_(“type”) == “high”)
val recordsArray: IndexedSeq[Map[String, Any]] = records.toIndexedSeq
val dataFeeder = recordsArray.circular

This toIndextedSeq is quite convenient :slight_smile:

Thanks for your help, it works like a charm.

Have a good one.