JMeter - Extract value from JSON response and update variable



  • My goal is to create a Google Drive CRUD with JMeter. I was able to upload files with proper OAuth configuration.

    However, I am struggling in extracting the response data to be used in further HTTP Requests.

    The response of the upload is this simple JSON:

    {
     "kind": "drive#file",
     "id": "blablabla",
     "name": "Untitled",
     "mimeType": "text/plain"
    }
    

    I would need to fetch this id in a PostProcessor component and update a JMeter variable with this value. This way I could reference to this value in the Read, Update and Delete requests.

    I've tried to use the JSON Extractor and BeanShell, but I was unsucessful.



  • If you want to extract this id value into a JMeter Variable the relevant Json Path query would be as simple as:

    $.id
    

    You can verify this yourself using JSON Path Tester mode of the View Results Tree listener

    enter image description here

    So if you add a JSON Extractor as a child of the request which returns the above JSON and configure it like:

    enter image description here

    JMeter will store it into id variable as it evidenced by the Debug Sampler:

    enter image description here

    Going forward you should be able to access this value as ${id} where required:

    enter image description here

    More information: API Testing With JMeter and the JSON Extractor



Suggested Topics

  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2