jsonjmeterjson-extract

Get the first key from JSON response using JMeter JSON extractor


I am getting below response while running an API.

{
    "bookingId": 0,
    "bookingIds": {
        "13320134": "2023-05-01T04:30:00",
        "13320135": "2023-05-02T04:30:00",
        "13320136": "2023-05-03T04:30:00"
    },
    "conflictDates": null,
    "recurrenceID": 1710459
}

I want to get the first value inside 'bookingIds'

13320134

What I tried:

$.bookingIds.13320134

Output

[
  "2023-05-01T04:30:00"
]

Is it possible using JSON extractor or do I need to achieve this using javascript?


Solution

  • I guess the Json Extractor is desined to extract the values and not keys.

    You can have multiple extractors to do the job for you

    1. Use the json extractor to get the entire bookingIds Object
    2. Use a Regex extractor to filter the first key from the extracted json output

    enter image description here

    enter image description here

    enter image description here