Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

154
Views
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 answers
Answer question

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 Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!