Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

199
Vistas
Accessing JSON with a variable using square bracket notation not working in node.js Javascript

I'm using node.js. I read an object from a file as JSON using.

vc_channels.json file:

{
  "​hangout-room": "hangout-room is a voice and/or video room for anything sfw and not necessarily related to meditation."
}

code to read:

  fileContent = fs.readFileSync('./vc_channels.json');
  vc_channels = JSON.parse(fileContent);

but then when I try to access:

          console.log(vc_channels);
          console.log(channel.name);
          item.topic = vc_channels[channel.name];
          console.log(item.topic);

The result is undefined: console.log

{
  '​hangout-room': 'hangout-room is a voice and/or video room for anything sfw and not necessarily related to meditation.'
}
hangout-room
undefined

Does anyone know what I'm doing wrongly?

about 4 years ago · Juan Pablo Isaza
1 Respuestas
Responde la pregunta

0

If I copy your text for vc_channels.json, I can see that there is a \u200b (Zero width space) inside the "​hangout-room" part:

enter image description here

In the snipped bellow we can see that the first ASCII code is 200b and we have 68 afterwards which is h and so on:

const x = "​hangout-room";

// This prints: [200b","68", "61", "6e", "67", "6f", "75", "74", "2d", "72", "6f", "6f", "6d"]
console.log(x.split('').map(c => c.charCodeAt().toString(16)));

So you just have to remove the zero width space character from there. Just copy the output of this into your json file: "​hangout-room".replace('/200b', '') Or use any text editor which can show this kind of weird characters and lets you remove it.

about 4 years ago · Juan Pablo Isaza Denunciar
Responde la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda