Does anyone have any suggestions for the following scenario:
I have a response in .json format containing personal data of a person, who may or may not be assigned to a project.
Here is an example response where the person is not assigned to a project:
"contactPerson": {
"id": "someUUID",
"firstName": "string",
"lastName": "string",
"email": "string",
"title": "string"
},
"project": null
And here is an example response where the person is assigned to a project:
"contactPerson": {
"id": "someUUID",
"firstName": "string",
"lastName": "string",
"email": "string",
"title": "string"
},
"project": {
"id": "projectUUID",
"name": "This is a project name ",
"fullName": "This is a full project name with over 55 chars",
}
I've tried using a simple if statement, but it hasn't been successful.
if (typeOf(response.body[i].project.id !== null) {
//assert elements in project array
} else {
//assert is 'null
}
However, I keep getting the following error:
Cannot read properties of null (reading 'id')
Does anyone have a solution on how to resolve this issue? I need to assert whether a project is assigned or not.
Thank you in advance