The whole file is an array and there are objects and other arrays (e.g. cars) in the whole array of the file.

As you say, the outermost layer of your JSON blob is an array. Therefore, your parser will return a JSONArray. You can then get JSONObjects from the array ...

  JSONArray a = (JSONArray) parser.parse(new FileReader("c:\\exer4-courses.json"));

  for (Object o : a)
  {
    JSONObject person = (JSONObject) o;

    String name = (String) person.get("name");
    System.out.println(name);

    String city = (String) person.get("city");
    System.out.println(city);

    String job = (String) person.get("job");
    System.out.println(job);

    JSONArray cars = (JSONArray) person.get("cars");

    for (Object c : cars)
    {
      System.out.println(c+"");
    }
  }

For reference, see "Example 1" on the json-simple decoding example page.

Answer from Greg Kopff on Stack Overflow
🌐
Attacomsian
attacomsian.com › blog › java-read-write-json-files
How to read and write JSON Files in Java
October 3, 2022 - Learn how to read and write JSON files using JSON.simple, Jackson, Gson, and Mushi open-source libraries.
Discussions

Parse json file in Java?
I'm curious what you googled that didn't return any results. You should use keywords to narrow it down to the official JavaDocs. JsonParser . At least this is a good place to start. More on reddit.com
🌐 r/learnprogramming
5
2
November 28, 2022
Read a JSON file with Java "org.json"
Says on the Github page of the library you're using JSONObject.java: The JSONObject can parse text from a String or a JSONTokener to produce a map-like object. [...] JSONTokener.java: The JSONTokener breaks a text into a sequence of individual tokens. It can be constructed from a String, Reader, or InputStream. So your program flow could be java.io.File -> java.io.FileReader -> org.json.JSONTokener -> org.json.JSONObject or java.io.File -> java.io.FileInputStream -> org.json.JSONTokener -> org.json.JSONObject or something similar. Just make sure to close your Reader/Stream at the appropriate time after processing the file, in order to not run into other problems later. More on reddit.com
🌐 r/javahelp
7
1
April 26, 2021
streaming a large json object to a file to avoid memory allocation error

Well, JSON.stringify and JSON.parse are synchronous methods that unfortunately you can't pipe to and from. Like u/nissen2 suggests, you'll find some modules out there that will provide you what you're looking for.

Ah, I think I got it. Is there a way to permanently increase the amount of memory that node has access to? Thx.

While this may solve your problem in the mean time, I wouldn't suggest simply allocating more memory (especially with a huge JSON object.)

More on reddit.com
🌐 r/node
16
0
October 14, 2014
How to edit json files
With serde you would either define structs to parse into, which you can then modify as normal: use serde::{Deserialize, Serialize}; #[derive(Deserialize, Serialize)] #[serde(rename_all = "camelCase")] struct Config { version: u32 } fn main() { let mut config: Config = serde_json::from_str(r#"{"version": 1}"#).expect("unable to parse JSON"); config.version += 1; println!("{}", serde_json::to_string_pretty(&config).expect("unable to serialize")); } or parse into a Value and manipulate that: use serde_json::Value; use std::collections::HashMap; fn main() { let mut config: HashMap = serde_json::from_str(r#"{"version": 1}"#).expect("unable to parse JSON"); if let Some(mut version) = config["version"].as_u64() { version += 1; config.insert("version".to_string(), Value::from(version)); } else { panic!("version is missing or not a number"); } println!( "{}", serde_json::to_string_pretty(&config).expect("unable to serialize") ); } It should be relatively obvious that the first version is much more ergonomic and should be preferred where possible. More on reddit.com
🌐 r/rust
5
1
January 13, 2019
🌐
Quora
quora.com › How-do-I-read-a-JSON-file-in-Java-from-a-current-directory
How to read a JSON file in Java from a current directory - Quora
Answer (1 of 4): You Can use JSON Parser API which is stable to read any JSON file below is the code for that . suppose your json file content will be like [code]{ "age":23, "name":"Anand Dwivedi" } [/code]then Java code should be [code]package ...
🌐
DZone
dzone.com › coding › java › how to read and parse a json file in java
How to Read and Parse a JSON File in Java
March 6, 2025 - To read the JSON file in Java, FileReader() method is used to read the given JSON file.
🌐
GeeksforGeeks
geeksforgeeks.org › java › working-with-json-data-in-java
Working with JSON Data in Java - GeeksforGeeks
December 23, 2025 - { "Student": [ { "Stu_id": "1001", "Stu_Name": "Ashish", "Course": "Java" }, { "Stu_id": "1002", "Stu_Name": "Rana", "Course": "Advance Java" } ] } To read and write JSON data in Java, we commonly use third-party libraries.
🌐
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 - JSON.simple is a lightweight JSON processing library that can be used to read and write JSON files and strings. The encoded/decoded JSON will be in full compliance with JSON specification (RFC4627). JSON.simple library is pretty old and has not been updated since march, 2012. Google GSON library is a good option for reading and writing JSON. In this Java JSON tutorial, we will first see a quick example of writing to a JSON file and then we will read JSON from the file.
Find elsewhere
🌐
GeeksforGeeks
geeksforgeeks.org › java › how-to-read-and-write-json-files-in-java
How to Read and Write JSON Files in Java? - GeeksforGeeks
February 4, 2026 - Then an ObjectMappe­r instance is created. It coverting Java obje­cts into JSON. Then readTree method is used to read the contents of the JSON file "mydata.json" and converts it into a JsonNode object.
🌐
Oracle
oracle.com › java › technical details
Java API for JSON Processing
JsonParser provides forward, read-only access to JSON data using the pull parsing programming model.
🌐
WordPress
luppeng.wordpress.com › 2019 › 11 › 09 › reading-json-from-textfile-in-java
Reading JSON from Textfile in Java – Technical Scratchpad
November 9, 2019 - I created the JSON object in a file called myData.json that looks like this: { "link" : "luppeng.wordpress.com", "type" : "website" } import java.io.IOException; import java.io.InputStream; import org.apache.commons.io.IOUtils; import org.json.JSONException; import org.json.JSONObject; public class ReadJsonClass { public static void main(String[] args) { try { InputStream is = ReadJsonClass.class.getResourceAsStream("myData.json"); String text = IOUtils.toString(is, "UTF-8"); JSONObject myJsonObject = new JSONObject(text); System.out.println(myJsonObject); } catch (IOException | JSONException e) { System.out.println("Try like you have never caught before"); } } }
🌐
CodeSignal
codesignal.com › learn › courses › handling-json-files-with-java › lessons › working-with-json-in-java-advanced-parsing-techniques
Accessing JSON Data with Java
In this lesson, you'll dive deeper into parsing JSON files, a crucial skill for working with diverse data sources using Java. Many web applications and APIs use JSON to send and receive data, making it essential for developers to parse JSON efficiently. This lesson focuses on utilizing the Jackson library in Java to read and parse JSON data from files, effectively leveraging JSON's structure within the Java environment.
🌐
DigitalOcean
digitalocean.com › community › tutorials › jackson-json-java-parser-api-example-tutorial
Jackson JSON Java Parser API Example Tutorial | DigitalOcean
August 3, 2022 - Employee Object ***** Employee Details ***** ID=123 Name=Pankaj Permanent=true Role=Manager Phone Numbers=[123456, 987654] Address=Albany Dr, San Jose, 95129 Cities=[Los Angeles, New York] Properties={age=29 years, salary=1000 USD} ***************************** Employee JSON is //printing same as above json file data · com.fasterxml.jackson.databind.ObjectMapper is the most important class in Jackson API that provides readValue() and writeValue() methods to transform JSON to Java Object and Java Object to JSON.
🌐
Coderanch
coderanch.com › t › 674356 › java › read-JSON-files-Gson
how to read JSON files using Gson [Solved] (Java in General forum at Coderanch)
December 30, 2016 - Also, you can simplify your reader. ... saeid jamali wrote:and the code for my user interface is Don't use ==, use equals. Otherwise the block will not get executed if your description is equal to JSON but is a different String instance.
🌐
Medium
medium.com › @AlexanderObregon › javas-jsonparser-parse-method-explained-76b126f6110e
Java’s JsonParser.parse() Method Explained | Medium
October 13, 2024 - The readObject() method processes the string and converts it into a JsonObject, allowing easy access to its fields. For real-world applications, JSON data often comes from files rather than hardcoded strings. Let’s look at an example that shows how to parse a JSON file and retrieve specific data. import javax.json.Json; import javax.json.JsonReader; import javax.json.JsonObject; import java.io.FileInputStream; import java.io.FileNotFoundException; public class JsonFileParserExample { public static void main(String[] args) { try { // Open the JSON file using a FileInputStream FileInputStream
🌐
DZone
dzone.com › data engineering › data › how to read json files in java using the google gson library
How to Read JSON Files in Java Using the Google Gson Library
November 5, 2024 - Next, the fromJson() method of the Gson library is used to parse the JSON data into the Java object. It accepts two parameters: the first one is the reader object that points to the JSON data in the file and the second one is the listCustomerDetailsType that provides the Type information to Gson so it can deserialize the JSON into List<CustomerDetails>.
🌐
Baeldung
baeldung.com › home › json › reading json from a url in java
Reading JSON From a URL in Java | Baeldung
January 8, 2024 - Moreover, it would also require even more code if we wanted to convert our JSON into a map or a POJO. Even using the new Java 11 HttpClient, it’s a lot of code for a simple GET request. Also, it doesn’t help with converting the response from strings to POJO. So, let’s explore simpler ways to do this. A very popular library is Apache Commons IO. We’ll use IOUtils to read a URL and get a String back.
🌐
Crunchify
crunchify.com › json tutorials › how to read json object from file in java?
How to Read JSON Object From File in Java? • Crunchify
February 16, 2023 - Hi Ashok – I hope this tutorial will help: https://crunchify.com/simple-oracle-database-jdbc-connect-and-executequery-example-in-java/ ... Here I am having one problem, if I have array of objects, then how can I read those JSON objects from array ? ... Object obj = parser.parse(new FileReader(COLLECTION_FILE_NAME)); JSONArray mainArray = (JSONArray) obj;
🌐
LabEx
labex.io › tutorials › java-how-to-read-json-file-from-relative-path-in-java-417587
How to read JSON file from relative path in Java | LabEx
When running a Maven project from the terminal, the working directory is typically the project's root folder, which is ~/project in our case. Therefore, the relative path to our JSON file is src/main/resources/data.json. Let's create a Java class to read the file.
🌐
W3Schools
w3schools.com › java › java_files.asp
Java Files
File handling is an important part of any application. Java has several methods for creating, reading, updating, and deleting files.
🌐
Attacomsian
attacomsian.com › blog › jackson-read-json-file
How to Read JSON from a file using Jackson
October 14, 2022 - The following example demonstrates how you can read the above JSON file into a Book object by using the readValue() method: try { // create object mapper instance ObjectMapper mapper = new ObjectMapper(); // convert a JSON string to a Book object ...