diff --git a/json/pom.xml b/json/pom.xml
index 23955e5a75..7a6d57c28e 100644
--- a/json/pom.xml
+++ b/json/pom.xml
@@ -73,6 +73,12 @@
${commons-collections4.version}
test
+
+ org.assertj
+ assertj-core
+ ${assertj-core.version}
+ test
+
@@ -86,6 +92,7 @@
2.9.7
4.12
1.1.2
+ 3.11.1
diff --git a/json/src/main/java/com/baeldung/jsonobject/iterate/JSONObjectIterator.java b/json/src/main/java/com/baeldung/jsonobject/iterate/JSONObjectIterator.java
new file mode 100644
index 0000000000..0ff8650652
--- /dev/null
+++ b/json/src/main/java/com/baeldung/jsonobject/iterate/JSONObjectIterator.java
@@ -0,0 +1,50 @@
+package com.baeldung.jsonobject.iterate;
+
+import java.util.HashMap;
+import java.util.Iterator;
+import java.util.Map;
+
+import org.json.JSONArray;
+import org.json.JSONObject;
+
+public class JSONObjectIterator {
+
+ private Map keyValuePairs;
+
+ public JSONObjectIterator() {
+ keyValuePairs = new HashMap<>();
+ }
+
+ public void handleValue(String key, Object value) {
+ if (value instanceof JSONArray) {
+ handleJSONArray(key, (JSONArray) value);
+ } else if (value instanceof JSONObject) {
+ handleJSONObject((JSONObject) value);
+ }
+ keyValuePairs.put(key, value);
+ }
+
+ public void handleJSONObject(JSONObject jsonObject) {
+ Iterator jsonObjectIterator = jsonObject.keys();
+ jsonObjectIterator.forEachRemaining(key -> {
+ Object value = jsonObject.get(key);
+ handleValue(key, value);
+ });
+ }
+
+ public void handleJSONArray(String key, JSONArray jsonArray) {
+ Iterator