JSONObject json = new JSONObject(yourdata);
String statistics = json.getString("statistics");
JSONObject name1 = json.getJSONObject("John");
String ageJohn = name1.getString("Age");

For getting those items in a dynamic way:

JSONObject json = new JSONObject(yourdata);
String statistics = json.getString("statistics");

for (Iterator key=json.keys();key.hasNext();) {
    JSONObject name = json.get(key.next());
    //now name contains the firstname, and so on... 
}
Answer from Emanuel on Stack Overflow
🌐
Oracle
docs.oracle.com › javaee › 7 › api › javax › json › JsonObject.html
JsonObject (Java(TM) EE 7 Specification APIs)
javax.json · All Superinterfaces: JsonStructure, JsonValue, Map<String,JsonValue> public interface JsonObject extends JsonStructure, Map<String,JsonValue> JsonObject class represents an immutable JSON object value (an unordered collection of zero or more name/value pairs).
🌐
Baeldung
baeldung.com › home › json › introduction to json-java (org.json)
Introduction to JSON-Java | Baeldung
June 20, 2025 - CDL – a tool that provides methods ... – a standard exception thrown by this library · A JSONObject is an unordered collection of key and value pairs, resembling Java’s native Map implementations....
🌐
GeeksforGeeks
geeksforgeeks.org › java › working-with-json-data-in-java
Working with JSON Data in Java - GeeksforGeeks
December 23, 2025 - JSON encoding means converting Java data into JSON format. Example: Create and Print JSON Object. ... import org.json.simple.JSONObject; public class JavaJsonEncoding { public static void main(String[] args) { JSONObject jsonObject = new ...
🌐
Stleary
stleary.github.io › JSON-java › org › json › JSONObject.html
JSONObject
A JSONObject is an unordered collection of name/value pairs. Its external form is a string wrapped in curly braces with colons between the names and values, and commas between the values and names. The internal form is an object having get and opt methods for accessing the values by name, and ...
🌐
TutorialsPoint
tutorialspoint.com › json › json_java_example.htm
JSON with Java
Following is another example that shows a JSON object streaming using Java JSONObject − · import org.json.simple.JSONObject; class JsonEncodeDemo { public static void main(String[] args) { JSONObject obj = new JSONObject(); obj.put("name","foo"); obj.put("num",new Integer(100)); obj.put("balance",new Double(1000.21)); obj.put("is_vip",new Boolean(true)); StringWriter out = new StringWriter(); obj.writeJSONString(out); String jsonText = out.toString(); System.out.print(jsonText); } }
🌐
Processing
processing.github.io › processing-javadocs › core › processing › data › JSONObject.html
JSONObject
A JSONObject is an unordered collection of name/value pairs. Its external form is a string wrapped in curly braces with colons between the names and values, and commas between the values and names. The internal form is an object having get and opt methods for accessing the values by name, and ...
🌐
Medium
medium.com › @papapapaya11 › exploring-various-ways-to-handle-jsonobject-in-java-6edef1f0561c
Exploring Various Ways to Handle JSONObject in Java | by Little Miss Brave | Medium
December 2, 2024 - String jsonTemplate = "{\"greeting\": \"Hello, ${name}!\", \"age\": ${age}}"; Map<String, String> values = new HashMap<>(); values.put("name", "Little Miss Brave"); values.put("age", "26"); StringSubstitutor substitutor = new StringSubstitutor(values); String result = substitutor.replace(jsonTemplate); JSONObject jsonObject = JSONObject.fromObject(result); System.out.println(jsonObject); // {"greeting": "Hello, Little Miss Brave!", "age": 26} If there are other special use cases, they will be continuously updated here. By mastering these methods, you’ll be well-equipped to handle JSON data efficiently in Java applications.
Find elsewhere
🌐
SourceForge
json-lib.sourceforge.net › apidocs › net › sf › json › JSONObject.html
JSONObject (Overview (json-lib jdk 1.3 API))
A JSONObject is an unordered collection of name/value pairs. Its external form is a string wrapped in curly braces with colons between the names and values, and commas between the values and names. The internal form is an object having get and opt methods for accessing the values by name, and ...
🌐
Oracle
docs.oracle.com › cd › F10042_01 › reference-java-api › oracle › adfmf › json › JSONObject.html
JSONObject (Oracle Fusion Middleware Java API Reference for Oracle Mobile Application Framework)
Oracle Fusion Middleware Java API Reference for Oracle Mobile Application Framework 2.5.1.0.0 E92592-01 ... A JSONObject is an unordered collection of name/value pairs. Its external form is a string wrapped in curly braces with colons between the names and values, and commas between the values ...
🌐
GitHub
github.com › stleary › JSON-java › blob › master › src › main › java › org › json › JSONObject.java
JSON-java/src/main/java/org/json/JSONObject.java at master · stleary/JSON-java
private static void attemptWriteValue(Writer writer, int indentFactor, int indent, Entry<String, ?> entry, String key) { ... "JSONObject[" + quote(key) + "] is not a " + valueType + " (" + value.getClass() + ")."
Author   stleary
🌐
Android Developers
developer.android.com › api reference › jsonobject
JSONObject | API reference | Android Developers
Skip to main content · English · Deutsch · Español – América Latina · Français · Indonesia · Polski · Português – Brasil · Tiếng Việt · 中文 – 简体
🌐
SourceForge
json-lib.sourceforge.net › apidocs › jdk15 › net › sf › json › JSONObject.html
JSONObject (Overview (json-lib jdk 5 API))
A JSONObject is an unordered collection of name/value pairs. Its external form is a string wrapped in curly braces with colons between the names and values, and commas between the values and names. The internal form is an object having get and opt methods for accessing the values by name, and ...
🌐
Oracle
docs.oracle.com › javame › 8.0 › api › json › api › com › oracle › json › JsonObject.html
JsonObject (JSON Documentation)
JsonStructure, JsonValue, java.util.Map<java.lang.String,JsonValue> public interface JsonObject extends JsonStructure, java.util.Map<java.lang.String,JsonValue> JsonObject class represents an immutable JSON object value (an unordered collection of zero or more name/value pairs).
Top answer
1 of 5
158

I'm assuming you want to store the interestKeys in a list.

Using the org.json library:

JSONObject obj = new JSONObject("{interests : [{interestKey:Dogs}, {interestKey:Cats}]}");

List<String> list = new ArrayList<String>();
JSONArray array = obj.getJSONArray("interests");
for(int i = 0 ; i < array.length() ; i++){
    list.add(array.getJSONObject(i).getString("interestKey"));
}
2 of 5
13
public class JsonParsing {

public static Properties properties = null;

public static JSONObject jsonObject = null;

static {
    properties = new Properties();
}

public static void main(String[] args) {

    try {

        JSONParser jsonParser = new JSONParser();

        File file = new File("src/main/java/read.json");

        Object object = jsonParser.parse(new FileReader(file));

        jsonObject = (JSONObject) object;

        parseJson(jsonObject);

    } catch (Exception ex) {
        ex.printStackTrace();
    }
}

public static void getArray(Object object2) throws ParseException {

    JSONArray jsonArr = (JSONArray) object2;

    for (int k = 0; k < jsonArr.size(); k++) {

        if (jsonArr.get(k) instanceof JSONObject) {
            parseJson((JSONObject) jsonArr.get(k));
        } else {
            System.out.println(jsonArr.get(k));
        }

    }
}

public static void parseJson(JSONObject jsonObject) throws ParseException {

    Set<Object> set = jsonObject.keySet();
    Iterator<Object> iterator = set.iterator();
    while (iterator.hasNext()) {
        Object obj = iterator.next();
        if (jsonObject.get(obj) instanceof JSONArray) {
            System.out.println(obj.toString());
            getArray(jsonObject.get(obj));
        } else {
            if (jsonObject.get(obj) instanceof JSONObject) {
                parseJson((JSONObject) jsonObject.get(obj));
            } else {
                System.out.println(obj.toString() + "\t"
                        + jsonObject.get(obj));
            }
        }
    }
}}
🌐
Miamarti
miamarti.github.io › HorusFramework › javadoc › org › json › simple › JSONObject.html
JSONObject
A JSON object. Key value pairs are unordered. JSONObject supports java.util.Map interface.
🌐
Scaler
scaler.com › topics › jsonobject-java
JsonObject Java - Scaler Topics
January 6, 2023 - A JSONObject is a collection of name/value pairs that are not ordered. The string's external form is enclosed in curly braces and has commas between values and names and colons between names and values.
🌐
Couchbase
docs.couchbase.com › sdk-api › couchbase-java-client › com › couchbase › client › java › json › JsonObject.html
JsonObject (Couchbase Java SDK 3.11.1 API)
Constructs a JsonObject from a Map<String, ?>. This is only possible if the given Map is well formed, that is it contains non null keys, and all values are of a supported type. A null input Map or null key will lead to a NullPointerException being thrown. If any unsupported value is present in the Map, an InvalidArgumentException will be thrown.