Hi I want to test with assertThat
if a JSONArray contains an item with a key with a specific value. For example I have JSONArray:
[
{
"eventType": "event_1",
"name": "user_1",
....
},
{
"eventType": "event_2",
"name": "user_2",
....
}
]
What I want to test is if this array contains an item with the key: eventType
with the value: event_2
Is it possible to achieve this with assertThat
without looping through the array and checking each item?
I know it is possible to check if a map contains a given key and value and I also know it is possible to check if an array contains given item. But I didn't found any solution how to combine both things. Someone has an idea how can I combine these two things?
Thank you for your help
This is best addressed by https://github.com/lukas-krecan/JsonUnit which will give you much better JSON assertions than the generic AssertJ.
Hope it helps!
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.