Seems like you can't iterate through JSONArray with a for each. You can loop through your JSONArray like this:

for (int i=0; i < arr.length(); i++) {
    arr.getJSONObject(i);
}

Source

Answer from dguay on Stack Overflow
Discussions

How to loop through an array with JSON objects
const arr = [ {title: " some title", id: "some id"}, {title: " some title2", id: "some id2"} ] console.log( "For loop") for( let i = 0; i< arr.length; i++) { console.log(arr[i].id) } console.log( "Use of") for ( let item of arr) { console.log( item.id) } console.log( "Use forEach - recommended") arr.forEach( (item) => console.log( item.id)); console.log( "Use forEach plus destructuring - recommended") arr.forEach( ({id}) => console.log( id)); console.log( "Use map to transform array, then log array") const result = arr.map( ({id}) => id) ; console.log( result) Output: For loop some id some id2 Use of some id some id2 Use forEach - recommended some id some id2 Use forEach plus destructuring - recommended some id some id2 Use map to transform array, then log array [ 'some id', 'some id2' ] P.S. If you are using var to declare a variable, you probably shouldn't be. Use const and let where possible. More on reddit.com
🌐 r/learnjavascript
9
4
December 30, 2022
How to print the Json Array using for each loop
Hi Guys, Below is my JsonResponse of type JsonArray and I want to iterate through this using for each loop. Can you please help if you have solved similar kind of problem? JsonResponse [{“predictions”:1,“confidences… More on forum.uipath.com
🌐 forum.uipath.com
1
1
January 19, 2022
java - foreach on json array - Stack Overflow
I have two java applications. In both of them I am iterating json array using foreach: More on stackoverflow.com
🌐 stackoverflow.com
How do I iterate over a JSON structure?
Here is something quite similar in pure JavaScript, using JavaScript's forEach method. forEach takes a function as an argument. That function will then be called for each item in the array, with said item as the argument. More on stackoverflow.com
🌐 stackoverflow.com
🌐
ZetCode
zetcode.com › javascript › jsonforeach
JavaScript JSON forEach - Iterating Over JSON Arrays
This code defines a JSON array of users, where each user has a name and a nested array of tasks. Each task has a title and a completion status. We use forEach to iterate over the users and their tasks, printing the user's name and each task's title and completion status to the console.
🌐
Reddit
reddit.com › r/learnjavascript › how to loop through an array with json objects
r/learnjavascript on Reddit: How to loop through an array with JSON objects
December 30, 2022 -

Hi all,

Im really struggling with this problem today. So basically, I have an array in the format

arr = [{title: " some title", id: "some id"}, {title: " some title2", id: "some id2"}] and all im trying to do is loop through each item in the array and get the value of the ids.

Here is what ive tried:

for( var i = 0; i< arr.length; i++){

console.log(arr[i].id)

}

It keeps showing up as undefined, please can anyone assist me? I would like the result to be "some id"

🌐
GitHub
gist.github.com › chancesmith › 8d21d966b69eff170fae7fa4e5cfb4f5
Foreach loop through JSON object array · GitHub
Foreach loop through JSON object array. GitHub Gist: instantly share code, notes, and snippets.
🌐
GeeksforGeeks
geeksforgeeks.org › javascript › how-to-iterate-json-object-in-javascript
How to Iterate JSON Object in JavaScript? - GeeksforGeeks
July 23, 2025 - The forEach method can then be applied to iterate through the array of entries. Inside the loop, both the key and value of each property can be accessed directly. ... const obj = { "company": 'GeeksforGeeks', "contact": '+91-9876543210', "city": ...
Find elsewhere
🌐
Microverse
microverse.org › home › blog › how to loop through the array of json objects in javascript
How to Loop Through the Array of JSON Objects in JavaScript
September 29, 2022 - This method is used for looping through an array element. Here’s an example of this: {% code-block language="js" %} var names = ["jerry", "tom", "pluto", "micky", "mini"]; names.forEach(function1); function function1(currentValue, index) { ...
🌐
Splunk Community
community.splunk.com › t5 › Splunk-Search › How-to-use-foreach-to-extract-value-from-another-json-object › m-p › 642068
How to use foreach to extract value from another json object?
May 3, 2023 - However when it's used in the foreach loop, the limits values aren't in the new_data_limits variable. ... | makeresults | eval limits=json_object("process1", json_array(123), "process2", json_array(234), "process3", json_array(0.12)), total=0 | eval processes = json_array("process1", "process2") | eval new_data_limits = json_object() | foreach processes [ | eval key = tostring(<<FIELD>>), value = json_extract(limits, key), new_data_limits = if(isnull(new_data_limits), json_object(key, value), json_set(new_data_limits, key, value)) ] get average base search | stats avg(*) as * by process1, process2
🌐
TutorialsPoint
tutorialspoint.com › parsing-json-array-with-php-foreach
Parsing JSON array with PHP foreach
April 7, 2020 - <?php $json_array ='{ "values": { "a": "abc", "d": 0, "efg": 349 } }'; $array = json_decode($json_array, true); foreach($array as $values) { echo $values['efg']; echo $values['d']; echo $values['a']; }
🌐
Microsoft Power Platform Community
powerusers.microsoft.com › t5 › General-Power-Automate › How-to-do-a-foreach-in-an-json-array-and-append-some-variable › td-p › 84797
How to do a foreach in an json array and append so...
January 26, 2018 - Quickly search for answers, join discussions, post questions, and work smarter in your business applications by joining the Microsoft Dynamics 365 Community.
🌐
Stack Overflow
stackoverflow.com › questions › 48185286 › foreach-from-array-json-data
php - Foreach from array json data - Stack Overflow
You are using json_decode(..., true), so the returned $myArray is an array, and all its sub items are all arrays. <?php $response = ' [{ "id": 782, "name": "Test Translation New", "price": "1", "image": { "url": "xxx/image-2.jpg", "position": 0 }, "link": "https:xxx", "nickname": "newmarker" }, { "id": 777, "name": "Test Translation", "price": "0", "image": { "url": "https:xxx/image-1.jpg", "position": 0 }, "link": "https:xxx", "nickname": "newmarker" }] '; $myArray = json_decode($response, true); foreach ($myArray as $product) { echo $product['name'] .
🌐
SitePoint
sitepoint.com › blog › javascript › how to loop through a json response in javascript
How to Loop Through a JSON Response in JavaScript — SitePoint
February 15, 2024 - Parsing JSON data from a server involves two steps: first, decoding the JSON string into a native JavaScript data structure (such as an array or object), and then iterating over this structure using JavaScript’s built-in methods like for...in, Object.entries, Object.values, or array methods such as forEach.
🌐
Javatpoint
javatpoint.com › iterate-json-array-java
Iterate JSON Array Java - Javatpoint
Iterate JSON Array Java with java tutorial, features, history, variables, object, programs, operators, oops concept, array, string, map, math, methods, examples etc.