1

This brings me all the values ​​of the json file

Example: I have id, name and lastname, I want to bring the id value

  fs.readFile("user.json", function (err, data) {
    if (err) throw err;
    console.log(data.toString());
});

info file json

{"Identificador":0,"Nombre_Principal":"man","Nombre_Paterno":"man","Nombre_Materno":"man","Contrasena":"man","Correo":"man@man.com","Posicion":"User","Token":"eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJ1bmlxdWVfbmFtZSI6Im1hbiIsIm5iZiI6MTU0MjgzODU5OCwiZXhwIjoxNTQyODQwMzk4LCJpYXQiOjE1NDI4Mzg1OTgsImlzcyI6Imh0dHA6Ly9sb2NhbGhvc3Q6NjUyMjQiLCJhdWQiOiJodHRwOi8vbG9jYWxob3N0OjY1MjI0In0.W9Tck4QjzCoP2g0CdFIsmshSUoZbzi8AmzR9EnRYIVQ","Estatus":0}

1 Answers1

1

Before you can access the actual data inside the string containing JSON, you have to parse it first. Use JSON.parse() for this.

fs.readFile('user.json', function (err, data) {
  if (err) throw err;
  data = JSON.parse(data);  // Convert JSON into an actual JavaScript object
  console.log(data.Identificador); // Access object properties with the dot `.` notation
});
Brad
  • 159,648
  • 54
  • 349
  • 530