Q: How to assert that response returns an object with exact key and some int? My response to the endpoint /booking returns an array of objects that contain unique booking IDs:
[
  {
    "bookingid": 1
  },
  {
    "bookingid": 2
  },
  {
    "bookingid": 3
  },
  {
    "bookingid": 4
  }
]

It is pretty huge and random, so there is no way to store its example in the variable for subsequent comparison.
How Python can assert that response returns 1) exactly this object, 2) containing exactly this kind of pairs (bookingid and some int?)?
I.e. assert that response contains a list(?) of dictionaries?

A: "How can I assert that response returns 1) exactly this object, 2) containing exactly this kind of pairs (bookingid and some int?)"

*

*Just check for equality

:
x == [
  {
    "bookingid": 1
  },
  {
    "bookingid": 2
  },
  {
    "bookingid": 3
  },
  {
    "bookingid": 4
  }
]

x = [
{
"bookingid": 1
},
{
"bookingid": 2
},
{
"bookingid": 3
},
{
"bookingid": 4
}
]


*You can check the presence of that key and the type of the values, I had to guess your intention a bit because your question is not really clear, fell free to tell me if you meant this or something different:

:
def validate(x):
    for dictionary in x:
        for key, value in dictionary.items():
            # this asserts that the only allowed key is bookingid
            # change this part of the logic if you want to allow other keys
            if key != "bookingid":
                raise ValueError(f"Key {key} is not bookingid")
            if not isinstance(value, int):
                raise ValueError(f"Value {value} is not int")
    return True

print(validate(x))

