Hi you can use simple JSON. You just need to add in your pom.xml file:

<dependency>
        <groupId>com.googlecode.json-simple</groupId>
        <artifactId>json-simple</artifactId>
</dependency>

Sample code

public static JSONObject convertJsonStingToJson(String jsonString) {
    JSONParser parser = new JSONParser();
    return  json = (JSONObject) parser.parse(jsonString);
}
Answer from Vivek kumar on Stack Overflow
🌐
DigitalOcean
digitalocean.com › community › tutorials › json-simple-example
json-simple example | DigitalOcean
August 4, 2022 - package com.journaldev.json.write; import java.io.FileNotFoundException; import java.io.FileReader; import java.io.IOException; import java.io.Reader; import java.util.Iterator; import org.json.simple.JSONArray; import org.json.simple.JSONObject; import org.json.simple.parser.JSONParser; import org.json.simple.parser.ParseException; public class JsonSimpleReader { public static void main(String[] args) throws ParseException, FileNotFoundException, IOException { JSONParser parser = new JSONParser(); Reader reader = new FileReader("data.json"); Object jsonObj = parser.parse(reader); JSONObject j
🌐
Maven Repository
mvnrepository.com › artifact › com.googlecode.json-simple › json-simple › 1.1
Maven Repository: com.googlecode.json-simple » json-simple » 1.1
Indexed Artifacts (63.6M) · Popular Categories · Testing Frameworks & Tools · Android Packages · JVM Languages · Logging Frameworks · Java Specifications · JSON Libraries · Core Utilities · Mocking
🌐
Javadoc.io
javadoc.io › doc › javax.json › javax.json-api › 1.0-b01 › javax › json › stream › JsonParser.html
JsonParser (JSON-P API jar 1.0-b01 API)
Bookmarks · Latest version of javax.json:javax.json-api · https://javadoc.io/doc/javax.json/javax.json-api · Current version 1.0-b01 · https://javadoc.io/doc/javax.json/javax.json-api/1.0-b01 · package-list path (used for javadoc generation -link option) · https://javadoc.io/doc/java...
🌐
Javadoc.io
javadoc.io › doc › com.fasterxml.jackson.core › jackson-core › latest › com › fasterxml › jackson › core › JsonParser.html
JsonParser - jackson-core 2.21.1 javadoc
Bookmarks · Latest version of com.fasterxml.jackson.core:jackson-core · https://javadoc.io/doc/com.fasterxml.jackson.core/jackson-core · Current version 2.21.1 · https://javadoc.io/doc/com.fasterxml.jackson.core/jackson-core/2.21.1 · package-list path (used for javadoc generation -link ...
🌐
Jar-download
jar-download.com › maven-repository-class-search.php
Download dependencies for java class org.json.simple.parser.JSONParser
Here you can download the dependencies for the java class org.json.simple.parser.JSONParser. Use this engine to looking through the maven repository.
🌐
Jar-Download
jar-download.com › home › com.google.code.gson › gson › 2.8.0 › source code › jsonparser.java
com.google.gson.JsonParser Maven / Gradle / Ivy
*/ package com.google.gson; import java.io.IOException; import java.io.Reader; import java.io.StringReader; import com.google.gson.internal.Streams; import com.google.gson.stream.JsonReader; import com.google.gson.stream.JsonToken; import com.google.gson.stream.MalformedJsonException; /** * A parser to parse Json into a parse tree of {@link JsonElement}s * * @author Inderjeet Singh * @author Joel Leitch * @since 1.3 */ public final class JsonParser { /** * Parses the specified JSON string into a parse tree * * @param json JSON text * @return a parse tree of {@link JsonElement}s corresponding t
Find elsewhere
🌐
DigitalOcean
digitalocean.com › community › tutorials › jackson-json-java-parser-api-example-tutorial
Jackson JSON Java Parser API Example Tutorial | DigitalOcean
August 3, 2022 - package com.journaldev.jackson.json; import java.io.File; import java.io.IOException; import java.util.ArrayList; import java.util.HashMap; import java.util.List; import com.fasterxml.jackson.core.JsonFactory; import com.fasterxml.jackson.core.JsonParseException; import com.fasterxml.jackson.core.JsonParser; import com.fasterxml.jackson.core.JsonToken; import com.journaldev.jackson.model.Address; import com.journaldev.jackson.model.Employee; public class JacksonStreamingReadExample { public static void main(String[] args) throws JsonParseException, IOException { //create JsonParser object Json
🌐
GitHub
gist.github.com › 2c655016e1dca6d39d403e8f01e63dd2
Java Android JSON Parser Class · GitHub
Java Android JSON Parser Class. GitHub Gist: instantly share code, notes, and snippets.
🌐
Vertica
docs.vertica.com › 25.1.x › en › extending › developing-udxs › user-defined-load-udl › user-defined-parser › java-example-json-parser
Java example: JSON parser | Vertica 25.1.x
April 5, 2023 - => CREATE LIBRARY json -> AS '/opt/vertica/packages/flextable/examples/java/output/json.jar' -> DEPENDS '/opt/vertica/bin/gson-2.2.4.jar' language 'java'; CREATE LIBRARY => CREATE PARSER JsonParser AS LANGUAGE 'java' -> NAME 'com.vertica.flex.JsonParserFactory' LIBRARY json; CREATE PARSER FUNCTION
🌐
Vertica
docs.vertica.com › 24.1.x › en › extending › developing-udxs › user-defined-load-udl › user-defined-parser › java-example-json-parser
Java example: JSON parser | Vertica 24.1.x
April 5, 2023 - => CREATE LIBRARY json -> AS '/opt/vertica/packages/flextable/examples/java/output/json.jar' -> DEPENDS '/opt/vertica/bin/gson-2.2.4.jar' language 'java'; CREATE LIBRARY => CREATE PARSER JsonParser AS LANGUAGE 'java' -> NAME 'com.vertica.flex.JsonParserFactory' LIBRARY json; CREATE PARSER FUNCTION
🌐
Fasterxml
fasterxml.github.io › jackson-core › javadoc › 2.5 › com › fasterxml › jackson › core › JsonParser.html
JsonParser (Jackson-core 2.5.0 API)
Method to deserialize JSON content into a non-container type (it can be an array type, however): typically a bean, array or a wrapper type (like Boolean). Note: method can only be called if the parser has an object codec assigned; this is true for parsers constructed by MappingJsonFactory (from ...
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
🌐
GeeksforGeeks
geeksforgeeks.org › java › parse-json-java
How to parse JSON in Java - GeeksforGeeks
December 23, 2025 - 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.JSONParser; public class JSONReadExample { public static void main(String[] args) throws Exception { Object obj = new JSONParser().parse(new FileReader("JSONExample.json")); JSONObject jo = (JSONObject) obj; String firstName = (String) jo.get("firstName"); String lastName = (String) jo.get("lastName"); long age = (long) jo.get("age"); System.out.println(firstName); System.out.println(lastName); System.out.println(age); Ma
🌐
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
🌐
Vertica
docs.vertica.com › 11.1.x › en › extending › developing-udxs › user-defined-load-udl › user-defined-parser › java-example-json-parser
Java example: JSON parser | Vertica 11.1.x
July 14, 2023 - => CREATE LIBRARY json -> AS '/opt/vertica/packages/flextable/examples/java/output/json.jar' -> DEPENDS '/opt/vertica/bin/gson-2.2.4.jar' language 'java'; CREATE LIBRARY => CREATE PARSER JsonParser AS LANGUAGE 'java' -> NAME 'com.vertica.flex.JsonParserFactory' LIBRARY json; CREATE PARSER FUNCTION
🌐
Google Code
code.google.com › archive › p › json-simple › downloads
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
🌐
TutorialsPoint
tutorialspoint.com › home › json_simple › json simple quick guide
JSON Simple Quick Guide
March 14, 2013 - Discover how to effectively use JSON Simple for parsing JSON data in Java with our quick guide.