Search code examples
jsonjmeterjson-extract

Regex for JMeter JSON Extractor


I'm using JMeter to validate some HTTPS requests, and for that, I'm using one JSON extractor and I want to extract data from the JSON response I'm getting. So from the below payload, I want to extract oper_state from any resource where service_name is equal to "Japan-1-3-12_service".

{   
"resource":[
    { 
        "id":"de04c6b1-a5a3-11ec-a02b-765e38f104a5-19",
        "name":"Tokyo-1-1-10",
        "service_name":"Tokyo-1-1-10_service",
        "oper_state":"UP",
        "type":"admin"
    },
    {
        "id":"me05c6b1-a903-11ec-a02b-764313f104a5-19",
        "name":"Japan-1-3-12",
        "service_name":"Japan-1-3-12_service",
        "oper_state":"UP",
        "type":"admin"
    },
    { 
        "id":"5e04c691-a5a3-11ec-a02b-765e38f3q4a5-19",
        "name":"France-1-1-3",
        "service_name":"France-1-1-3_service",
        "oper_state":"DOWN",
        "type":"admin"
    }
    ]}

I was using "$.resource[?(@.service_name=="Japan-1-3-12_service")].operational_state", but not getting any output in the variable.

enter image description here


Solution

  • Why you're using operational_state when in your JSON response it's oper_state everywhere?

    Just change your JSON Path query to

    $.resource[?(@.service_name=="Japan-1-3-12_service")].oper_state
    

    and it should start working as expected

    enter image description here

    More information: JMeter's JSON Path Extractor Plugin - Advanced Usage Scenarios