Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

155
Visualizações
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 Respostas
Responde à pergunta

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 Relatório
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda