I am validating the tags of a JSON that is as follows:
[{
"Person": [{
"Id": 1,
"Type": 1,
"Extra": [{
"Number": 88888888,
"Code": 506
}],
"Personal": {
"Name": "Mario"
}
},
{
"Id": 1,
"Type": 1,
"Extra": [{
"Number": 88888888,
"Code": 506
}],
"Personal": {
"Name": "Mario"
}
}]
},
{
"Person": [{
"Id": 1,
"Type": 1,
"Extra": [{
"Number": 88888888,
"Code": 506
}],
"Personal": {
"Name": "Mario"
}
},
{
"Id": 1,
"Type": 1,
"Extra": [{
"Number": 88888888,
"Code": 506
}],
"Personal": {
"Name": "Mario",
"Last name":"Portuguez",
"Country": "España"
}
}]
}]
And I have been validating the JSON with this code:
var properties = ["Id", "Type", "Extra", "Personal"];
var properties2 = ["Number","Code"];
var fine = 0;
var wrong = 0;
jsonFile.forEach( f =>{
f.Notification.forEach(function( i ){
//Sacar los índices de la corrida en la que vamos
let dataKeys = Object.keys( i );
//Ciclamos el arreglo de las llaves
dataKeys.forEach(function( x ){
if(properties.indexOf( x ) > -1){
fine = 1;
}else{
error = 3;
throw new Error("Error code: E0003 \n Validation code: V0003 \n Description: JSON do not have the correct format.")
}
if(fine === 1){
jsonFile.forEach( f =>{
f.Notification.forEach(e =>{
e.Means.forEach(function(v){
let data = Object.keys(v);
data.forEach(function( x ){
if(properties2.indexOf( x ) > -1){
fine = 1;
}else{
wrong = 1;
throw new Error("Error code: E0003 \n Validation code: V0003 \n Description: JSON do not have the correct format.")
}
})
})
})
})
}
});
});
})
}
And everything works as it should be, but as you can see in the code, it only validates "Extra" but I can not make it validate "Personal" ... could you give me an example?
THANK YOU!