# Iterate throw JSON array values

**URL:** <https://discourse.processing.org/t/iterate-throw-json-array-values/1710>\
**Category:** Coding Questions\
**Created:** [July 12, 2018, 7:39am UTC](https://discourse.processing.org/t/iterate-throw-json-array-values/1710 "2018-07-12T07:39:25Z")\
**Posts on this page:** 1\
**Showing post:** 2

<div class="post-metadata">

**Author:** ![WakeMeAtThree](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/wakemeatthree/32/38_2.png) [@WakeMeAtThree](https://discourse.processing.org/u/WakeMeAtThree)\
**Post date:** [July 12, 2018, 1:04pm UTC](https://discourse.processing.org/t/iterate-throw-json-array-values/1710/2 "2018-07-12T13:04:48Z")

</div>

Hi mloiz!  
The issue is that the array you loaded has two types, integers and strings, stored in the array. You should load them using getInt() and getString(), and to solve the alternating key issue, just use mod. Here’s one way to do this with your code:

```auto
JSONObject json;

void setup() {
  json = loadJSONObject("data.json");
  JSONObject child = json.getJSONObject("facet_counts");
  JSONObject child2 = child.getJSONObject("facet_fields");
  JSONArray array = child2.getJSONArray("structHasAuthIdHal_fs");
  println(array.size());

  for (int i = 0; i< array.size(); i++) {
    if (i%2==0) {
      println(array.getString(i));
    } else {
      println(array.getInt(i));
    }
  }
  exit();
}

```

Also, try not to name things after common object names, like `array` for example, and try to keep your json properly indented to read.

---

_[View the full topic](https://discourse.processing.org/t/iterate-throw-json-array-values/1710)._
