jmeterblazemetertaurus

Taurus: Pull numerical value (no quotes) from CSV into JSON


How can I pull data from a CSV into JSON without adding a quote?

This is what I want generated:

{"id" : 12345} 

I have a rest service that only allows a numeric value, but I'm unable to pull from the CSV without adding quotes.

body: { "id": "${id}"}

Works, but it adds quote to the message {"id" : "12345"}

body: { "id" : {id} } 

returns:

 Error when reading config file 'test.yml': while parsing a flow mapping
  in "<unicode string>", line 34, column 13:
          body: { "id": ${id} }
                ^
expected ',' or '}', but got '{'
  in "<unicode string>", line 34, column 22:
          body: { "id": ${id} }

Solution

  • According to documentation you need to put the body string into quotation marks:

    body: '{ "id": ${id}}'
    

    Full example just in case you want to validate the approach:

    execution:
      - concurrency: 1
        scenario: quick-test
    scenarios:
      quick-test:
        requests:
          - url: 'http://example.com'
            jsr223:
              - language: groovy
                execute: before
                script-text: 'vars.put("id", "12345")'
            method: POST
            body: '{ "id": ${id}}'
    

    More information: