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....
Discussions

Parsing JSON object using Java
Unless this is an exercise to use a lower level library like org.json, I would strongly recommend using something that helps with the mapping to Java like Jackson instead More on reddit.com
🌐 r/javahelp
11
1
November 11, 2021
Can't import "json-20240303" library into my project.
Show your pom.xml More on reddit.com
🌐 r/javahelp
7
2
June 17, 2024
Cannot configure JSON in eclipse (The type org.json.JSONObject is not accessible)
Please ensure that: Your code is properly formatted as code block - see the sidebar (About on mobile) for instructions You include any and all error messages in full You ask clear questions You demonstrate effort in solving your question/problem - plain posting your assignments is forbidden (and such posts will be removed) as is asking for or giving solutions. Trying to solve problems on your own is a very important skill. Also, see Learn to help yourself in the sidebar If any of the above points is not met, your post can and will be removed without further warning. Code is to be formatted as code block (old reddit: empty line before the code, each code line indented by 4 spaces, new reddit: https://i.imgur.com/EJ7tqek.png ) or linked via an external code hoster, like pastebin.com, github gist, github, bitbucket, gitlab, etc. Please, do not use triple backticks (```) as they will only render properly on new reddit, not on old reddit. Code blocks look like this: public class HelloWorld { public static void main(String[] args) { System.out.println("Hello World!"); } } You do not need to repost unless your post has been removed by a moderator. Just use the edit function of reddit to make sure your post complies with the above. If your post has remained in violation of these rules for a prolonged period of time (at least an hour), a moderator may remove it at their discretion. In this case, they will comment with an explanation on why it has been removed, and you will be required to resubmit the entire post following the proper procedures. To potential helpers Please, do not help if any of the above points are not met, rather report the post. We are trying to improve the quality of posts here. In helping people who can't be bothered to comply with the above points, you are doing the community a disservice. I am a bot, and this action was performed automatically. Please contact the moderators of this subreddit if you have any questions or concerns. More on reddit.com
🌐 r/javahelp
1
1
August 5, 2022
How to parse json to get size of the list using jsonObject in java?
Please ensure that: Your code is properly formatted as code block - see the sidebar (About on mobile) for instructions You include any and all error messages in full You ask clear questions You demonstrate effort in solving your question/problem - plain posting your assignments is forbidden (and such posts will be removed) as is asking for or giving solutions. Trying to solve problems on your own is a very important skill. Also, see Learn to help yourself in the sidebar If any of the above points is not met, your post can and will be removed without further warning. Code is to be formatted as code block (old reddit: empty line before the code, each code line indented by 4 spaces, new reddit: https://imgur.com/a/fgoFFis ) or linked via an external code hoster, like pastebin.com, github gist, github, bitbucket, gitlab, etc. Please, do not use triple backticks (```) as they will only render properly on new reddit, not on old reddit. Code blocks look like this: public class HelloWorld { public static void main(String[] args) { System.out.println("Hello World!"); } } You do not need to repost unless your post has been removed by a moderator. Just use the edit function of reddit to make sure your post complies with the above. If your post has remained in violation of these rules for a prolonged period of time (at least an hour), a moderator may remove it at their discretion. In this case, they will comment with an explanation on why it has been removed, and you will be required to resubmit the entire post following the proper procedures. To potential helpers Please, do not help if any of the above points are not met, rather report the post. We are trying to improve the quality of posts here. In helping people who can't be bothered to comply with the above points, you are doing the community a disservice. I am a bot, and this action was performed automatically. Please contact the moderators of this subreddit if you have any questions or concerns. More on reddit.com
🌐 r/javahelp
4
1
February 10, 2022
🌐
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.