Hello everyone, good morning.
First of all, i am a begginer to this subjects and English is not my native language.
Thx for the help.
I am developing a test script in javascript which gets values from a JSON response.
See the example below:
HTTP/1.1 200 OK
Content-Type: application/vnd.api+json
{
"data": [{
"type": "articles",
"id": "1",
"attributes": {
"title": "JSON API paints my bikeshed!",
"body": "The shortest article. Ever.",
"created": "2015-05-22T14:56:29.000Z",
"updated": "2015-05-22T14:56:28.000Z"
},
"relationships": {
"author": {
"data": {"id": "42", "type": "people"}
}
}
}],
"included": [
{
"type": "people",
"id": "42",
"attributes": {
"name": "John",
"age": 80,
"gender": "male"
}
}
]
}
However, for some reason, some variables that should come in my JSON script are missing and for that reason my assertions are failing. (imagine for example that i will assert the gender from the response with the expected gender, but the response gender is missing as if the code didn`t even had gender from the start).
I believe it happens because the gender camp is optional.
In JAVA/groovy i know that i could use ? to ignore the missing variables... How can i do the same in javascript.
What I have tried:
i am trying with If/Else, but i`ve failed. Anyway i want to use a shorter solution and more optimized to solve that problem. The closer i get from ? the better,