0

I have the following json:

{
"content":
[
    {
        "id":1,
        "userId":2,
        "storeId":8,
        "userFirstName":"Max",
        "userLastName":"Mustermann",
       "city":"Berlin",
        "spendQuantity":100,

        "paymentStatus":"UNPAID",
        "userBalanceStatus":null,
        "rateObject":
        {
            "identifier":23,
            "id":"432",
            "rate":"1.9345345",
            "symbol":"USD",
            "rank":2,

        }
    },
    {
        "id":2,
        "userId":2,
        "storeId":3,
        "userFirstName":"Newman",
        "userLastName":"Mustermann",
       "city":"Berlin",
        "spendQuantity":1000,

        "paymentStatus":"UNPAID",
        "userBalanceStatus":null,
        "rateObject":
        {
            "identifier":3,
            "id":"234",
              "rate":"1.922222245345",
            "symbol":"USD",
            "rank":2,

        }
    },
    {
        "id":3,
        "userId":2,
        "storeId":3,
        "userFirstName":"Newman",
        "userLastName":"Mustermann",
       "city":"Munich",
        "spendQuantity":3000,

        "paymentStatus":"UNPAID",
        "userBalanceStatus":null,
        "rateObject":
        {
            "identifier":2332,
            "id":"234",
               "rate":"3.234234",
            "symbol":"USD",
            "rank":2,

        }
    },
    {
        "id":4,
        "userId":2,
        "storeId":3,
        "userFirstName":"Newman",
        "userLastName":"Mustermann",
       "city":"Essen",
        "spendQuantity":4000,

        "paymentStatus":"UNPAID",
        "userBalanceStatus":null,
        "rateObject":
        {
            "identifier":234,
            "id":"234",
               "rate":"333.234234",
            "symbol":"USD",
            "rank":2,

        }
    }

}

But I need to verify it partially - Only the fields in the nested jsons where city is Berlin or Essen, but without the rateObject (I don't need to verify this part). With other words I need to verify nested jsons with ids- 1,2,4 - all fields, without the information in rateObject.

Nelly
  • 137
  • 2
  • 10

1 Answers1

0

Partial Answer and Suggestion:

  1. We can apply the filter condition in the JSON Query to fetch the matched details.

For Example: To get the id of the mentioned city,

JSON Query:

$.content[?(@.city=="Berlin" || @.city=="Essen")].id

Output:

[
    1,
    2,
    4
]

Similarly, you can assert all the required fields using the filter JSON Query. JMeter JSON Extractor will provide only one value at a time.So, you can either add some logic to verify all the occurrences or multiple verification can be added by specifying the id index ( $.content[?(@.city=="Berlin" || @.city=="Essen")].id[0] --> It gives the first occurrence Id )

  1. If you want to validate multiple fields,then you can write the customized script in Bean Shell Post Processor.(Refer the below link and you will get some idea)

Extracting JSON Response using Bean Shell Postprocessor

If you are using the Bean Shell Post Processor, then required java jar files should be placed in JMeter ClassPath( Folder: apache-jmeter-4.0\lib\ext)

Subburaj
  • 2,294
  • 3
  • 20
  • 37