Estoy intentando validar si existe un array dentro de un JSON, la idea es poder validar cuando recibo el json que ese campo exista, si no existe entonces tiro el error:
{
"id": 113524,
"name": "John",
"Array": [
"name":"Anthony",
"value":"A"
]
}
Estoy leyendo el array en una variable:
let json = req.body;
let jsonData = JSON.stringify(json);
let jsonValue = JSON.parse(jsonData);
let jsonSpecificValue = jsonValue.Array[0].value;
Si quiero validar que venga ese Array en el json intento algo como:
if(!jsonValue['Array']){
console.error('Error');
}
El error que me está dando es el siguiente:
(node:20056) UnhandledPromiseRejectionWarning: TypeError: Cannot read property '0' of undefined
El error apunta a la variable jsonSpecificValue.
Como puedo validar que existe ese Array en el JSON ???