How to Compare an array from one Json Response to an array from another Json response.
SOLVED- Bookmark
- Subscribe
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
How to Compare an array from one Json Response to an array from another Json response.
Hi All,
I have 2 different json array and need to validate every n each attribute against each other .Earlier I used Message content assertion but I need to do for all array item manually. for example there is array for "Route"
is there any other way to compare array of response ?
Solved! Go to Solution.
- Labels:
-
Assertions
-
REST
- Bookmark
- Subscribe
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Extract the data from the response body (JSON object array) in the form of JSON string Glasshouse view of code quality with every check-in In automating the requests, we need to pass the data in many requests in different forms.
- Bookmark
- Subscribe
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Regards,
Rao.
- Bookmark
- Subscribe
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
- Bookmark
- Subscribe
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Here is a sample to compare two lists (books in this case). But you need to adopt the changes as per your data.
def expectedJson = '''{
"book": [
{
"title": "Beginning JSON",
"price": 49.99
},
{
"title": "JSON at Work",
"price": 29.99
}
]
}'''
def actualJson = '''{
"book": [
{
"title": "JSON at Work",
"price": 29.99
},
{
"title": "Beginning JSON",
"price": 49.99
}
]
}'''
//Note that the order of books are different in the above
def getJson = { str -> new groovy.json.JsonSlurper().parseText(str)}
def expectedBooks = getJson(expectedJson).book
def actualBooks = getJson(actualJson).book
//Check if both lists are sorted and compared
assert actualBooks.sort() == expectedBooks.sort()
Regards,
Rao.
- Bookmark
- Subscribe
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
- Bookmark
- Subscribe
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Such an amazing story please share more stuff I really like these posts.
- Bookmark
- Subscribe
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
I have seen the first-time Article it is so wonderful thanks for sharing this article.
- Bookmark
- Subscribe
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
I have seen this article this is very nice thanks for sharing it with us.
- Bookmark
- Subscribe
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
