1) Assuming you have the JSON libraries on your path (from www.json.org), it's pretty easy.

import org.json.JSONTokener;
...

URI uri = new URI("http://someserver/data.json");
JSONTokener tokener = new JSONTokener(uri.toURL().openStream());
JSONObject root = new JSONObject(tokener);

From there, you can address the various parts of the JSON object. Take a look at the Javadocs for the specifics. https://developer.android.com/reference/org/json/package-summary.html

Answer from JohnnyO on Stack Overflow
🌐
Miamarti
miamarti.github.io › HorusFramework › javadoc › org › json › simple › parser › JSONParser.html
JSONParser
org.json.simple.parser.JSONParser · public class JSONParser extends java.lang.Object · Parser for JSON text. Please note that JSONParser is NOT thread-safe. Author: FangYidong · equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait · public static final int S_INIT ·
🌐
Tabnine
tabnine.com › home page › code › java › org.json.simple.parser.jsonparser
org.json.simple.parser.JSONParser java code examples | Tabnine
@Override public List<String> getSSTFilesFromMeta(Path localMetaPath) throws Exception { if (localMetaPath.toFile().isDirectory() || !localMetaPath.toFile().exists()) throw new InvalidPathException( localMetaPath.toString(), "Input path is either directory or do not exist"); List<String> result = new ArrayList<>(); JSONParser jsonParser = new JSONParser(); org.json.simple.JSONArray fileList = (org.json.simple.JSONArray) jsonParser.parse(new FileReader(localMetaPath.toFile())); fileList.forEach(entry -> result.add(entry.toString())); return result; } origin: GlowstoneMC/Glowstone ·
🌐
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.
🌐
JSON Formatter
jsonformatter.org › json-parser
JSON Parser Online to parse JSON
Online JSON Parser helps to parse, view, analyze JSON data in Tree View.
🌐
GitHub
github.com › fangyidong › json-simple › blob › master › src › main › java › org › json › simple › parser › JSONParser.java
json-simple/src/main/java/org/json/simple/parser/JSONParser.java at master · fangyidong/json-simple
A simple Java toolkit for JSON. You can use json-simple to encode or decode JSON text. - json-simple/src/main/java/org/json/simple/parser/JSONParser.java at master · fangyidong/json-simple
Author   fangyidong
🌐
DigitalOcean
digitalocean.com › community › tutorials › json-simple-example
json-simple example | DigitalOcean
August 4, 2022 - For reading JSON from file, we have to use org.json.simple.parser.JSONParser class. JSONParser parse method returns JSONObject. Then we can retrieve values by passing key names.
🌐
Tabnine
tabnine.com › home page › code › java › org.json.simple.parser.jsonparser
org.json.simple.parser.JSONParser.parse java code examples | Tabnine
JSONParser jsonParser = new JSONParser(); JSONObject jsonObject = (JSONObject) jsonParser.parse(obj); JSONArray lang = (JSONArray) jsonObject.get("Headlines"); JSONArray tag = lang.getJSONArray("tag"); for (int i = 0; i < tag .length(); i++) ...
Find elsewhere
🌐
GitHub
gist.github.com › 5254834
JSON parser on top of JSON.org · GitHub
JSON parser on top of JSON.org · Raw · JSONParser.java · This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
🌐
TutorialsPoint
tutorialspoint.com › json_simple › json_simple_quick_guide.htm
JSON.simple - Quick Guide
import java.io.IOException; import java.util.List; import java.util.Stack; import org.json.simple.JSONArray; import org.json.simple.JSONObject; import org.json.simple.parser.ContentHandler; import org.json.simple.parser.JSONParser; import org.json.simple.parser.ParseException; class JsonDemo { public static void main(String[] args) { JSONParser parser = new JSONParser(); String text = "{\"first\": 123, \"second\": [4, 5, 6], \"third\": 789}"; try { CustomContentHandler handler = new CustomContentHandler(); parser.parse(text, handler,true); } catch(ParseException pe) { } } } class CustomContent
🌐
Studytrails
studytrails.com › 2016 › 09 › 12 › java-org-json
parse Json for Java – org.json – Studytrails
September 12, 2016 - org.json.JSONTokener – This class parses a JSON string and is also used internally by the JSONObject and JSONArray classes to parse JSON Strings
🌐
Baeldung
baeldung.com › home › json › introduction to json-java (org.json)
Introduction to JSON-Java (org.json)
June 20, 2025 - In this tutorial, we’ll see how to create, manipulate, and parse JSON using one of the available JSON processing libraries in Java – the JSON-Java library, also known as org.json.
🌐
GitHub
github.com › stleary › JSON-java
GitHub - stleary/JSON-java: A reference implementation of a JSON package in Java. · GitHub
The JSON-Java package is a reference implementation that demonstrates how to parse JSON documents into Java objects and how to generate new JSON documents from the Java classes.
Starred by 4.7K users
Forked by 2.6K users
Languages   Java
🌐
GeeksforGeeks
geeksforgeeks.org › java › what-is-json-java-org-json
What is JSON-Java (org.json)? - GeeksforGeeks
July 17, 2022 - // importing JSON simple libraries import java.io.FileReader; import java.util.Iterator; import java.util.Map; import org.json.simple.JSONArray; import org.json.simple.JSONObject; import org.json.simple.parser.*; public class JSONReadExample { public static void main(String[] args) throws Exception { // The file JSON.json is parsed Object object = new JSONParser().parse(new FileReader("author.json")); // objc is convereted to JSON object JSONObject jsonObject = (JSONObject)object; // obtaining the fname and lname String firstName = (String)jsonObject.get("firstName"); String lastName = (String
🌐
Javadoc.io
javadoc.io › doc › org.json › json › latest › index.html
json 20251224 javadoc (org.json)
Latest version of org.json:json · https://javadoc.io/doc/org.json/json · Current version 20251224 · https://javadoc.io/doc/org.json/json/20251224 · package-list path (used for javadoc generation -link option) https://javadoc.io/doc/org.json/json/20251224/package-list ·
Top answer
1 of 16
962

The org.json library is easy to use.

Just remember (while casting or using methods like getJSONObject and getJSONArray) that in JSON notation

  • [ … ] represents an array, so library will parse it to JSONArray
  • { … } represents an object, so library will parse it to JSONObject

Example code below:

import org.json.*;

String jsonString = ... ; //assign your JSON String here
JSONObject obj = new JSONObject(jsonString);
String pageName = obj.getJSONObject("pageInfo").getString("pageName");

JSONArray arr = obj.getJSONArray("posts"); // notice that `"posts": [...]`
for (int i = 0; i < arr.length(); i++)
{
    String post_id = arr.getJSONObject(i).getString("post_id");
    ......
}

You may find more examples from: Parse JSON in Java

Downloadable jar: http://mvnrepository.com/artifact/org.json/json

2 of 16
714

For the sake of the example lets assume you have a class Person with just a name.

private class Person {
    public String name;

    public Person(String name) {
        this.name = name;
    }
}

Jackson (Maven)

My personal favourite and probably the most widely used.

ObjectMapper mapper = new ObjectMapper();

// De-serialize to an object
Person user = mapper.readValue("{\"name\": \"John\"}", Person.class);
System.out.println(user.name); //John

// Read a single attribute
JsonNode nameNode = mapper.readTree("{\"name\": \"John\"}");
System.out.println(nameNode.get("name").asText());

Google GSON (Maven)

Gson g = new Gson();

// De-serialize to an object
Person person = g.fromJson("{\"name\": \"John\"}", Person.class);
System.out.println(person.name); //John

// Read a single attribute
JsonObject jsonObject = new JsonParser().parseString("{\"name\": \"John\"}").getAsJsonObject();
System.out.println(jsonObject.get("name").getAsString()); //John

Org.JSON (Maven)

This suggestion is listed here simply because it appears to be quite popular due to stackoverflow reference to it. I would not recommend using it as it is more a proof-of-concept project than an actual library.

JSONObject obj = new JSONObject("{\"name\": \"John\"}");

System.out.println(obj.getString("name")); //John
🌐
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.