3
votes

I'm trying to use the extracted value in Body Data of another request. I extracted the value using JSON Path Extractor like below

enter image description here

value is extracted from the below response enter image description here

I used it like this in Body data

  {
    "TransactionId": ${transactionId},
    "Cancelled": false
  }

but this is not working in JMeter it shows the transactionId as ["223"]. I want it to be only 223

enter image description here

3

3 Answers

6
votes

We can do this in different ways, but I prefer to use "Jmeter" functionality (better to avoid plugins). For source git link

1. Using "Regular Expression Extractor" post processor.
2. Using "JSON Path PostProcessor" post processor.
  1. "Regular Expression Extractor": Regular Expression Extractor is no of the best functionality.

    Regular Expression: "transactionId":"(.+?)" Template: $1$ Match Number: 1

enter image description here 2."JSON Path PostProcessor": I never used this post processor, it's also good. Below is the expression

JSON path Expression : $.transactionId Match Numbers: 1

enter image description here

Please find the Results in Debugger Sampler, in "view Results tree"

enter image description here

2
votes

Substitute your $..transactionId JSON Path Expression with this one:

$..transactionId[0]

It should remove these JSON Array brackets and you will see 223 only as the ${transactionId} variable value

See Advanced Usage of the JSON Path Extractor in JMeter article for more tips on working with JSON response types.

1
votes

In JMeter 3.1 version on-wards, try with following JSON Path expression using JSON Extractor (which is built-in)

JSON Path expression: $.transactionId
Match No: 1

gave me 265 value. with out double quotes, without array symbol.

Json extractor screenshot:

enter image description here

View results tree screenshot

enter image description here