BruceyBandit
BruceyBandit

Reputation: 4334

assert a json field that contans a dot

i have a json response that outputs the following:

{
  "message": "The request is invalid.",
  "modelState": {
    "request.xxx": [
      "The field xxx must be between xxx and xxx."
    ],
    "request.xxx": [
      "The field xxx must be between xxx and xxx."
    ],
    "request.xxx[0].xxx": [
      "The field xxx must be between xxx and xxx."
    ]
  }
}

Now usually in script assertion we would find levels in a json by entering the field name of the json separated by a . As an example if I want to find request.xxxHotelId, to find it I will go def xxxhotelid = json.modelState.request.xxxrHotelId.

But as you can see the problem is the . in between request and xxxHotelID. Because there's a ., it would think request and xxxHotelID are on different levels so it would not find this field within the response.

My question is how to find the field request.xxxHotelId?

Upvotes: 0

Views: 127

Answers (1)

tim_yates
tim_yates

Reputation: 171194

It's as easy as

def juniperhotelid = json.modelState.'request.JuniperHotelId'

Upvotes: 2

Related Questions