# JSON URL Fetch and data filtering

**URL:** <https://forum.freecodecamp.org/t/json-url-fetch-and-data-filtering/378963>\
**Category:** General\
**Created:** [April 25, 2020, 11:12pm UTC](https://forum.freecodecamp.org/t/json-url-fetch-and-data-filtering/378963 "2020-04-25T23:12:38Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![TheBigCat](https://sea3.discourse-cdn.com/freecodecamp/user_avatar/forum.freecodecamp.org/thebigcat/32/144906_2.png) [@TheBigCat](https://forum.freecodecamp.org/u/TheBigCat)\
**Post date:** [April 25, 2020, 11:12pm UTC](https://forum.freecodecamp.org/t/json-url-fetch-and-data-filtering/378963/1 "2020-04-25T23:12:38Z")

</div>

This code does a great job of fetching and rendering everything within the JSON array, but what if I am interested in only listing the objects with a particular key-value (like gender)?

Since I’m not filtering during the fetch, what statement would I need to add in between the ‘const getListOfNames’ and ‘return’ statements to output the data I want?

```auto
const URL = "https://ghibliapi.herokuapp.com/people";

const main = document.getElementById("main");
main.innerHTML = "<p>Loading...";

fetch(URL).then((response) => response.json()).then((people) => main.innerHTML = getListOfNames(people));

const getListOfNames = (people) => {
  const names = people.map((person) => `<li>${person.name} - ${person.gender} </li>`).join("\n");

  return `<ul>${names}</ul>`;
};

```

---

<div class="post-metadata">

**Author:** ![chuckadams](https://sea3.discourse-cdn.com/freecodecamp/user_avatar/forum.freecodecamp.org/chuckadams/32/109651_2.png) [@chuckadams](https://forum.freecodecamp.org/u/chuckadams)\
**Post date:** [April 25, 2020, 11:20pm UTC](https://forum.freecodecamp.org/t/json-url-fetch-and-data-filtering/378963/2 "2020-04-25T23:20:55Z")

</div>

add `.filter(person => person.gender === 'cheese')` after your .map

( might need to edit that 🙂 )

---

<div class="post-metadata">

**Author:** ![TheBigCat](https://sea3.discourse-cdn.com/freecodecamp/user_avatar/forum.freecodecamp.org/thebigcat/32/144906_2.png) [@TheBigCat](https://forum.freecodecamp.org/u/TheBigCat)\
**Post date:** [April 25, 2020, 11:38pm UTC](https://forum.freecodecamp.org/t/json-url-fetch-and-data-filtering/378963/3 "2020-04-25T23:38:14Z")

</div>

Whaaaaa… BRILLIANT, Mr. Chuck! 😃 😃 😃

Okay, so that worked perfect when I added your code (and removed the cheese) above the .map statement. Adding it after the .map just kept the page in “Loading…”

Thanks, for all your help!

---

<div class="post-metadata">

**Author:** ![ILM](https://sea3.discourse-cdn.com/freecodecamp/user_avatar/forum.freecodecamp.org/ilm/32/363239_2.png) [@ILM](https://forum.freecodecamp.org/u/ILM)\
**Post date:** [June 1, 2021, 6:57pm UTC](https://forum.freecodecamp.org/t/json-url-fetch-and-data-filtering/378963/4 "2021-06-01T18:57:52Z")

</div>

Closed on June 1, 2021, 6:57pm UTC


