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

228
Views
How can I console.log an individual attribute from a JSON payload object?

I am trying to console.log some JSON values from an OpeanSea api call payload. I can successfully hit the end point as seen in the console when I run this:

await fetch(`https://api.opensea.io/api/v1/collections?asset_owner=${currentAccount}&offset=0&limit=300`, options)
.then(response => response.json())
.then(response => console.log("collection owned by current address", response))

but when I try to log only one attribute from the response object:

await fetch(`https://api.opensea.io/api/v1/collections?asset_owner=${currentAccount}&offset=0&limit=300`, options)
  .then(response => response.json())
  .then(({ assetts }) => {
    assetts.forEach((attributes) => {
      console.log(attributes.name)
    })
  })

I see

TypeError: Cannot read properties of undefined (reading 'forEach')

Is

assetts

an arbitrary name to iterate through? I think this is what i dont understand

about 4 years ago · Juan Pablo Isaza
1 answers
Answer question

0

You should know the structure of json and target the required attributes. Like in your case its collections array which is array of object and each object contains name key so you can target key like:

await fetch(`https://api.opensea.io/api/v1/collections?asset_owner=${currentAccount}&offset=0&limit=300`, options)
    .then((response) => {
      return response.json();
    })
    .then((assetts) => {
      assetts.collections.forEach((attributes) => {
        console.log(attributes.name);
      });
    })
    .catch((error) => {
      console.log({ error });
    });

In your first then block you should have to return response after parsing it, if you want to use the parsed data in next then block.

Tip: It is a good practice if you also handle error by putting catch block after then block.

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!