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

101
Views
Get JSON from URL, return array and count instances

I'm trying to map the JSON from the URL to an array but I think my mapping of the data isn't correct. I want to find every value inside of attributes and count how many instances of each value there are in the JSON file/ array.

[
  {
    name: "1",
    attributes: [
      {
        trait_type: "hat",
        value: "blue"
      },
      {
        trait_type: "hair",
        value: "red"
      }
    ]
  } 
];

$.getJSON(
  "https://jsonware.com/api/v1/json/3c53cbcd-5351-4fba-8b89-5f1fb009e857",
  function (data) {
    var items = $.map(data.attributes, function (i) {
      return i.value;
      const result = data.reduce(
        (acc, curr) => ((acc[curr] = (acc[curr] || 0) + 1), acc),
        {}
      );
      console.log(result);
      console.log(items);
    });
  }
);
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>

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

0

It is not clear what you want from the call.

There will me no code run after return i.value; so the console.logs will not run

The values you are getting cannot be added.

Here I get an array of all values. jQuery not needed

fetch(
  "https://jsonware.com/api/v1/json/3c53cbcd-5351-4fba-8b89-5f1fb009e857")
  .then(response => response.json())
  .then(data => { 
    const values = Object.values(data).flatMap(item => ({[item.name]:item.attributes.map(attr => attr.value )}))
    values.forEach(val => console.log(Object.keys(val)[0],Object.values(val)[0].length)) 
    const allValues = Object.values(data).map(item => item.attributes.map(attr => attr.value ))
    console.log("All values: ",allValues.length,allValues)
  }
);
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>

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!