Json Feeder exmple


I’ve been looking for a solid jsonFile (feeder) usage example but couldn’t find any, seems like most example are for csv.
I have a simple JSON array:


Code Snippet:

val usersDataSource = jsonFile("test.json").circular val scn = scenario("test") .feed(userDataSource) .exec(http("test1")) .post("/url") .body() .check(status.is(200))

  1. What am i supposed to put in “.body(???)” ?

  2. does the feeder simply iterate over the json array endlessly…?

  3. should i use the ‘repeat’ ChainBuilder ?

  4. in CSV i use the ‘body(StringBody(${some_expression}))’ - what is the jsonFile feeder equivalent ?

i’m sure i’m missing something here…

Thanks ! :slight_smile:

  1. Up to you.


(note: this doc has been improved but not published yet, will be along RC6)

For example .body(StringBody("""{“id”: ${id}}"""))

  1. The feeder isn’t in charge of iterating, just of feeding. circular means it won’t run out of records: after reaching the last one, cursor will move back to top.

iterating = looping (repeat, during, etc), or running concurrent users.

  1. See above.

  2. Well, that’s the same. Maybe you failed to realize how jsonFile feeder works: it expects an array of objects, that are the records, and on injecting, copy the fields as attributes.

See doc: http://gatling.io/docs/2.0.0-RC5/session/feeder.html?highlight=feeder#json-feeders

If you want to inject full JSON bodies, you probably want to use tsv (unlikely to have a tab in JSON) and have one JSON string per line.

  1. This is great, just what I was missing !
  2. I meant feeding by iterating :wink:
    3 + 4. The documentation made it all clear - thank you !

Glad to hear :slight_smile: