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

159
Vistas
JS: Cant grab json key

I am submitting a JSON and trying to access the individual keys.

I have tried it in different ways in the meantime.

    const jsonData = target.getAttribute('datas');
    console.log(jsonData.id); // returns undefined

    const jsonData = target.getAttribute('datas');
    console.log(jsonData[0].id); // returns undefined

    for(let key of Object.keys(jsonData)) {
        console.log(key);
    } // returns every single letter

    for (const [key, value] of Object.entries(jsonData)) {
        console.log(`${key}: ${value}`);
    } // returns every single letter

idk why. i dont need to parse the json. Every code explain do it same like one variant of mine.

// EDIT

The JSON:

{"id":"adf6cfce022e4798b11f3ae6bcd8dc0f","manufacturer":"..ö..","productName":"Blue Boat XL","productNumber":"A80801902","worth":[{"currencyId":"b7d2554b0ce847cd82f3ac9bd1c0dfca","net":11.05,"gross":11.9,"linked":false,"listPrice":null,"percentage":null,"regulationPrice":null,"extensions":[]}]}

still no access

const jsonData = JSON.parse(target.getAttribute('datas'));
    console.log(jsonData.id);

// THE SOLUTION // double parse LMAO

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

0

sounds like you haven't parsed the data - I'm guessing jsonData is actually a string as a result. You need to use JSON.parse to convert the string into an object.

try:

const jsonData = JSON.parse(target.getAttribute('datas'));
console.log(jsonData);

.. and see what you get.

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