JSONPath JavaScript. If node exists

Based on standard output of Zabbix API response, if the response from API call is:
{
  "jsonrpc": "2.0",
  "result": [
	{
		"userid": "4",
		"username": "asdf",
		"name": "ghjk",
		"surname": "qwerty",
		"url": "",
		"autologin": "1",
		"autologout": "0",
		"lang": "en_US",
		"refresh": "30s",
		"theme": "default",
		"attempt_failed": "0",
		"attempt_ip": "192.168.100.243",
		"attempt_clock": "1606382960",
		"rows_per_page": "50",
		"timezone": "default",
		"roleid": "3",
		"medias": [
			{
				"mediaid": "2",
				"userid": "4",
				"mediatypeid": "6",
				"sendto": [
					"x@y.z"
				],
				"active": "1",
				"severity": "63",
				"period": "1-7,00:00-24:00"
			}
		]
	}
  ],
  "id": 1
}
Preprocessing:
var jsonData=JSON.parse(value).result;

var result = [];

for(var el = 0; el < jsonData.length; el++){

// define new row
var row = {};

// extract and insert data
row["userid"] = jsonData[el].userid;
row["username"] = jsonData[el].username;

row["name"] = jsonData[el].name;
//row["medias"] = jsonData[el].medias.length;

// if media array is bigger than 0
if (jsonData[el].medias.length > 0){

// check if there is sendto node
if (jsonData[el].medias[0].sendto){
row["email"] = jsonData[el].medias[0].sendto[0];
}else{
row["email"] = "";
}
}else{
row["email"] = "";
}

// insert row into array
result.push(row);

}

// return jsonData.length;
return JSON.stringify(result);
After preprocessing, the outcome is:
[
  {
    "userid": "4",
    "username": "asdf",
    "name": "ghjk",
    "email": "x@y.z"
  }
]

No comments: