You need to find the JSONObject in the array first. You are trying to find the field natural of the top-level JSONObject, which only contains the field numbers so it is returning null because it can't find natural.

To fix this you must first get the numbers array.

Try this instead:

JSONParser parser = new JSONParser();
Object obj = parser.parse(new FileReader("...")); //the location of the file
JSONObject jsonObject = (JSONObject) obj;
JSONArray numbers = (JSONArray) jsonObject.get("numbers");

for (Object number : numbers) {
    JSONObject jsonNumber = (JSONObject) number;
    String natural = (String) jsonNumber.get("natural");
    System.out.println(natural);
}
Answer from Jeremy Hanlon on Stack Overflow
🌐
Mkyong
mkyong.com › home › java › read and write json using json.simple
Read and write JSON using JSON.simple - Mkyong.com
May 13, 2024 - Person person = new Person(); person.setName((String) jsonObject.get("name")); person.setAge(((Number) jsonObject.get("age")).intValue()); JsonArray jsonArray = (JsonArray) jsonObject.get("messages"); List<String> messages = new ArrayList<>(); for (Object obj : jsonArray) { messages.add((String) obj); } person.setMessages(messages); System.out.println(person); } catch (IOException | JsonException e) { throw new RuntimeException(e); } } } ... Founder of Mkyong.com, passionate Java and open-source technologies. If you enjoy my tutorials, consider making a donation to these charities. ... Mkyong.com has provided Java and Spring tutorials, guides, and code snippets since 2008. All published articles are simple, easy to understand, and well-tested in our development environment.
🌐
TutorialsPoint
tutorialspoint.com › home › json_simple › json simple quick guide
JSON Simple Quick Guide
March 14, 2013 - Explore the features of JSON Simple in this quick guide. Understand how to efficiently parse and generate JSON data in Java.
🌐
How to do in Java
howtodoinjava.com › home › java libraries › json.simple – read and write json
JSON.simple - Read and Write JSON in Java
October 1, 2022 - package com.howtodoinjava.demo.jsonsimple; import java.io.FileWriter; import java.io.IOException; import org.json.simple.JSONArray; import org.json.simple.JSONObject; public class WriteJSONExample { @SuppressWarnings("unchecked") public static void main( String[] args ) { //First Employee JSONObject employeeDetails = new JSONObject(); employeeDetails.put("firstName", "Lokesh"); employeeDetails.put("lastName", "Gupta"); employeeDetails.put("website", "howtodoinjava.com"); JSONObject employeeObject = new JSONObject(); employeeObject.put("employee", employeeDetails); //Second Employee JSONObject
🌐
GitHub
github.com › fangyidong › json-simple
GitHub - fangyidong/json-simple: A simple Java toolkit for JSON. You can use json-simple to encode or decode JSON text. · GitHub
A simple Java toolkit for JSON. You can use json-simple to encode or decode JSON text. - fangyidong/json-simple
Starred by 758 users
Forked by 343 users
Languages   Java
🌐
Google Code
code.google.com › archive › p › json-simple
Google Code Archive - Long-term storage for Google Code Project Hosting.
Archive · Skip to content · The Google Code Archive requires JavaScript to be enabled in your browser · Google · About Google · Privacy · Terms
🌐
Baeldung
baeldung.com › home › json › introduction to json-java (org.json)
Introduction to JSON-Java | Baeldung
June 20, 2025 - We use classes from the JSON-Java library to parse and manipulate JSON in Java. We also know this library as org.json. However, we should not confuse it with Google’s org.json.simple library.
Find elsewhere
🌐
Cliftonlabs
cliftonlabs.github.io › json-simple
json-simple
The json-simple library is meant to be a free lightweight utility for deserializing and serializing Javascript Object Notation (JSON).
🌐
Miamarti
miamarti.github.io › HorusFramework › javadoc › org › json › simple › JSONObject.html
JSONObject
public class JSONObject extends java.util.HashMap implements java.util.Map, JSONAware, JSONStreamAware
🌐
GitHub
github.com › RalleYTN › SimpleJSON
GitHub - RalleYTN/SimpleJSON: An improved version of json-simple for Java 11+
SimpleJSON is an improved version of json-simple for Java 11+.
Starred by 12 users
Forked by 8 users
Languages   Java 100.0% | Java 100.0%
🌐
Maven Repository
mvnrepository.com › artifact › com.googlecode.json-simple › json-simple
Maven Repository: com.googlecode.json-simple » json-simple
March 21, 2012 - Home » com.googlecode.json-simple » json-simple · A simple Java toolkit for JSON · LicenseApache 2.0 · CategoriesJSON Libraries · Tagsformatbundlejsongoogleserializationosgi · Ranking · #7358in MvnRepository · #60in JSON Libraries · HomePage http://code.google.com/p/json-simple/ 🔍 ...
🌐
Javatpoint
javatpoint.com › java-json-example
Java JSON Example
Java JSON example for beginners and professionals with examples of JSON with java, install json.simple, java json encode, java json encode using map, java json array encode, java json array encode using List, java json decode. Learn Java JSON example with array, object, schema, encode, decode, file, date etc.
🌐
Java Guides
javaguides.net › 2019 › 07 › jsonsimple-tutorial-read-and-write-json-in-java.html
JSON.simple Tutorial - Read and Write JSON in Java
September 12, 2016 - JSON.simple is a simple Java library for JSON processing, read and write JSON data and full compliance with JSON specification (RFC4627). In this JSON.simple tutorial, we will see quick examples to write JSON file with JSON.simple and then we ...
🌐
TutorialsPoint
tutorialspoint.com › json › json_java_example.htm
JSON with Java
JSON.simple maps entities from the left side to the right side while decoding or parsing, and maps entities from the right to the left while encoding. On decoding, the default concrete class of java.util.List is org.json.simple.JSONArray and the default concrete class of java.util.Map is org.json.simple.JSONObject.
🌐
Reddit
reddit.com › r/javahelp › jsonobject(org.json.simple) vs jsonobject(gson)
r/javahelp on Reddit: JSONObject(org.json.simple) vs JsonObject(Gson)
January 26, 2021 -

I don't know what's the difference between these two things.

Can I use two things in the same way?

Top answer
1 of 4
2
There are different libraries that you can use to deal with JSON. The org.json and GSON ones are both the ones you don't want to use. Jackson is the de-facto standard.
2 of 4
1
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.
🌐
Miamarti
miamarti.github.io › HorusFramework › javadoc › org › json › simple › parser › JSONParser.html
JSONParser
Parse JSON text into java object from the input source. ... Instance of the following: org.json.simple.JSONObject, org.json.simple.JSONArray, java.lang.String, java.lang.Number, java.lang.Boolean, null
🌐
Coderanch
coderanch.com › t › 693581 › java › org-json-simple-JSONObject-cast
org.json.simple.JSONObject cannot be cast to org.json.simple.JSONArray [Solved] (Beginning Java forum at Coderanch)
April 30, 2018 - import java.io.File; import java.io.FileNotFoundException; import java.io.FileReader; import java.io.IOException; import org.json.simple.JSONArray; import org.json.simple.JSONObject; import org.json.simple.parser.JSONParser; import org.json.simple.parser.ParseException; public class RWJson { @SuppressWarnings("unchecked") public static void main(String[] args) { File parentDir = new File("C://Users//sta2002//Downloads//2022-09-02_81450"); File elements[] = parentDir.listFiles(); for(File element: elements) { //System.out.println(element); File child = new File(element +"//TestResult"); System.
🌐
Oracle
docs.oracle.com › javaee › 7 › tutorial › jsonp001.htm
19.1 Introduction to JSON - Java Platform, Enterprise Edition: The Java EE Tutorial (Release 7)
The following example shows JSON data for a sample object that contains name-value pairs. The value for the name "phoneNumbers" is an array whose elements are two objects. { "firstName": "Duke", "lastName": "Java", "age": 18, "streetAddress": "100 Internet Dr", "city": "JavaTown", "state": "JA", "postalCode": "12345", "phoneNumbers": [ { "Mobile": "111-111-1111" }, { "Home": "222-222-2222" } ] }