plaidshirt
plaidshirt

Reputation: 5671

Failed to extract variables from JSON reponse in JMeter

I get response in JSON format in JMeter.

{"data1":{"file":"myfile","contentType":"text/xml"},"data2":{"file":"myfile","contentType":"text/xml"}}

I use jp@gc JSON Path Extractor plugin to get value of file fields. One instance for each.

Expression 1: $.data1.file

Expression 2: $.data2.file

I use Debug Sampler to check value of destination variables. None of these has value, when I check it there, but first one has value, when I use vars.get("destvar1") in a JSR223 Sampler. I tried also built-in JSON Post Processor, but produces same output.

Upvotes: 0

Views: 509

Answers (1)

Dmitri T
Dmitri T

Reputation: 168072

  1. Add JSON Extractor as a child of the request which returns the above JSON. JSON Extractor obeys JMeter Scoping Rules therefore you need to ensure that it is applied only to the "interesting" sampler
  2. Configure it as follows:

    • Name of created variables: destvar1;destvar2
    • JSON Path expressions: $.data1.file;$.data2.file
    • Default values: notfound;notfound

      enter image description here

  3. That's it, you should see the values using Debug Sampler and View Results Tree listener combination

    enter image description here

Upvotes: 1

Related Questions