scalaperformance-testingload-testinggatlingscala-gatling

Gatling Scala: Reading JSON Data


How do I feed JSON data into Gatling Scala? This line of code will take in comma delimited csv. Trying to edit code for json below

object GetProductScenario {
  val csvData = csv("data/get_products.csv").circular

  def exportScenario(): ScenarioBuilder = {
    scenario("Get Products")
      .exec(
        forever() {
          feed(csvData)
            .exec(GetProducts.searchData())
        }
      )
  }

JSON:

{
  "productId": 1,
  "name": "book",
  "amount": 17,

Solution

  • Have a look at StringBody or ElFileBody where you can use patterns like #{productId} to inject the desired values.