I tell you what I need to achieve, I have a json file and an array of objects. The object array with the info variable to know if it is the correct information, I should go through both and if for example the JSON the property TermLoteCupon === TermLoteCupon of the info variable I can have the information. If not it should give me an error the files are not the same.. What happens is that the json is big here I only show them with two, but it always has about 50... just like the other array of objects with the info variable (I did the calculation with info.length and it gave me 76.). To what I'm going, what I tried was wrong because I was able to compare the first one with the one that matches. That is, in summary, it should be iterating and comparing the fields of each one. If they are true, keep iterating and if not true, stop. Next I will leave implemented what I try.
JSON:
[{
"TermLoteCupon": "970766",
"Tarj": "1137587731",
"Trx": "Contr ctdo",
"Fecha del pago": "01/06/2022 00:43:32",
},
{
"TermLoteCupon": "970766",
"Tarj": "1137587731",
"Trx": "Contr ctdo",
"Fecha": "01/06/2022 00:43:32",
}],
ARRAY DE OBJETOS.
var info = [ {
Trx: 'Contr ctdo',
Fecha: '27/08/2022',
TermLoteCupon: '999999',
Tarj: '0180',
VentasconDto: '-5.000,00'
},
{
Trx: 'Contr ctdo',
Fecha: '07/08/2022',
TermLoteCupon: '999999',
Tarj: '0190',
VentasconDto: '-5.000,00'
},
]
let data = fs.readFileSync("../api/src/routes/prueba.json");
let jsonParseado = JSON.parse(data);
let Transacción = jsonParseado.Transacción;
let infoTable = JSON.stringify(newarray);
let infoParsed = JSON.parse(infoTable);
var TermLoteCupon = infoParsed.map((e) => e.TermLoteCupon).find((el) => el);
var Tarj = infoParsed.map((e) => e.Tarj).find((el) => el);
var VentasconDto = infoParsed.map((e) => e.VentasconDto).find((el) => el);
var Fecha = infoParsed.map((e) => e.Fecha).find((el) => el);
var Trx = infoParsed.map((e) => e.Trx).find((el) => el);
let comparacion = TermLoteCupon === Transacción;
console.log(
`La data de ambos es DATA: Y SON IGUALES? `,
comparacion
);
But as I said, this only returns a specific value. And for when you need to search for a single perfect piece of data, but at the moment it's multiple pieces of data. I wanted to try to make a for, but I have not found the necessary information, I did not know how to deal with it. Then, shortly, it would be to iterate the json and array of obj and compare their information if they are the same, continue iterating, if not, return an error. Thank you very much