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 ...
🌐
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.
🌐
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
Find elsewhere
🌐
Javadoc.io
javadoc.io › static › org.json › json › 20171018 › index.html
JSONObject (JSON in Java 20171018 API)
August 15, 2016 - JavaScript is disabled on your browser · Frame Alert · This document is designed to be viewed using the frames feature. If you see this message, you are using a non-frame-capable web client. Link to Non-frame version
🌐
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 › 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 ...
🌐
Coderanch
coderanch.com › t › 706235 › java › Identifying-JSONObject-JSONArray
Identifying JSONObject or JSONArray (Java in General forum at Coderanch)
I used a try/catch on the parser then caught a ParserException and processed it as an JSONArray instead an JSONObject. reply reply · Bookmark Topic Watch Topic · New Topic · Boost this thread! Similar Threads · Downloading JSON information and displaying it in a listview · Parse JSON in Java without knowing the incoming JSON format ·
🌐
Reddit
reddit.com › r/javahelp › parsing json object using java
r/javahelp on Reddit: Parsing JSON object using Java
November 11, 2021 -

I'm creating an application to pull data from yahoo finance API. One of the features is pulling historical data on a stock. The response from the API is a JSON Object:

{
  "AAPL": {
    "timestamp": [
      1643293800,
      1643380200,
      1643639400,
      1643725800,
      1643825174
    ],
    "symbol": "AAPL",
    "previousClose": null,
    "chartPreviousClose": 159.69,
    "end": null,
    "start": null,
    "close": [
      159.22,
      170.33,
      174.78,
      174.61,
      174.715
    ],
    "dataGranularity": 300
  },
  "GME": {
    "timestamp": [
      1643293800,
      1643380200,
      1643639400,
      1643725800,
      1643825135
    ],
    "symbol": "GME",
    "previousClose": null,
    "chartPreviousClose": 103.26,
    "end": null,
    "start": null,
    "close": [
      93.52,
      97.91,
      108.93,
      112.6,
      105.21
    ],
    "dataGranularity": 300
  }
}

The info I want to pull from this are the timestamp & close arrays for each stock. The code im currently playing with is:

       Response response = makeGetRequest(url);
      JSONObject jsonObject = new JSONObject(response.body());
      JSONObject responseObject = jsonObject.getJSONObject("AAPL");
      JSONArray timestampList = responseObject.getJSONArray("timestamp");

      for(int i = 0; i < timestampList.length(); i++){
        System.out.println(timestampList.get(i));
      }

Which presents the following error:

org.json.JSONException: JSONObject["AAPL"] not found.
	at org.json.JSONObject.get(JSONObject.java:580)
	at org.json.JSONObject.getJSONObject(JSONObject.java:790)
	at com.lyit.csd.marketapi.yahoo.YahooClient.getHistoricalInfo(YahooClient.java:58)
	at com.lyit.csd.app.PortfolioManager.getHistoricalData(PortfolioManager.java:220)
	at com.lyit.csd.app.Main.init(Main.java:56)
	at com.lyit.csd.app.Main.main(Main.java:14)

Any advice or alternative routes of approach for this problem would be greatly appreciated. It's worth mentioning this is my first time working with an API if im missing something obvious. I've attempted multiple ideas from stackoverflow already, using libraries such as Gson, jackson, json-simple. All to no avail. The current library being used is org.json

🌐
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 › @benpourian › how-to-create-a-java-object-from-a-json-object-c47c08b030c5
How to create a Java Object from a JSON object | by Benjamin Pourian | Medium
October 25, 2018 - This will be a very brief guide to creating a Java object from a JSON object using the popular gson` google library. I will first demonstrate a simple JSON → POJO example then follow that with another example where I will be using annotations provided by gson to instantiate a new object by capturing the relevant serialized name.
🌐
Maven Repository
mvnrepository.com › artifact › org.json › json
Maven Repository: org.json » json
December 24, 2025 - JSON is a light-weight, language independent, data interchange format. See http://www.JSON.org/ The files in this package implement JSON encoders/decoders in Java. It also includes the capability to convert between JSON and XML, HTTP headers, Cookies, and CDL.
🌐
Javadoc.io
javadoc.io › doc › com.google.code.gson › gson › 2.8.5 › com › google › gson › JsonObject.html
JsonObject - gson 2.8.5 javadoc
Bookmarks · Latest version of com.google.code.gson:gson · https://javadoc.io/doc/com.google.code.gson/gson · Current version 2.8.5 · https://javadoc.io/doc/com.google.code.gson/gson/2.8.5 · package-list path (used for javadoc generation -link option) · https://javadoc.io/doc/com.goog...
🌐
DigitalOcean
digitalocean.com › community › tutorials › java-json-example
Java JSON Example | DigitalOcean
August 4, 2022 - Streaming API - It’s similar to StaX Parser and good for large objects where you don’t want to keep whole object in memory. ... javax.json.JsonReader: We can use this to read JSON object or an array to JsonObject.
🌐
Cloudera Community
community.cloudera.com › t5 › Support-Questions › Converting-JSON-to-Java-Object-Array › td-p › 153155
Solved: Converting JSON to Java Object Array - Cloudera Community - 153155
February 1, 2017 - Error: Can not deserialize instance of java.lang.Object[] out of START_OBJECT token at [Source: {"f1":1,"f2":"abc"}; line: 1, column: 1] ... import org.json.JSONObject; public class JSONParser { public static void main(String[] args) { String jsonStr = "{\"field1\":1,\"field2\":\"abc\"}"; JSONObject json = new JSONObject(jsonStr); Person person = new Person(); person.setKey(json.getInt("field1")); person.setValue(json.getString("field2")); System.out.println(person.toString()); } }
🌐
W3Schools
w3schools.com › js › js_json_objects.asp
W3Schools.com
The data is only JSON when it is in a string format. When it is converted to a JavaScript variable, it becomes a JavaScript object.