I am not able to find any function or code snippets to fetch the keys (not data or value) from the response and compare with the keys of an external json.
If I have a requirement of comparing the keys between external json and response then how should I do it.
Example : The external json has client id, Salary, age where as the repose send client id , Salary, gender and Age then the test code should be able to generate errors for Gender as this is not expected in the response.
Lets say I have external json schema as
{
“data”: {
“id”: " ",
“first_name”: " ",
“last_name”: " ",
“avatar”: " "
}
}
Now if i wanted to compare each key like ‘id’ to see if it exists within response to see if it present in response or not.So my question are below
- How to read the external json using test code
- How to extract keys from that json
- how to compare with the response keys
I am intending to do it dynamically so that can reuse the same script for any other API testing