You are missing json-simple-1.1.1.jar from your classpath.

if you are using Maven, add below into your pom.xml.

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

Or you can download it from here.

Answer from Sundararaj Govindasamy on Stack Overflow
🌐
TutorialsPoint
tutorialspoint.com › org_json › org_json_quick_guide.htm
Org.Json - Quick Guide
JSONArray · JSONObject · Number · String · JSONObject.NULL object · package com.tutorialspoint; import org.json.JSONObject; public class JsonDemo { public static void main(String[] args) { JSONObject week = new JSONObject(); week.put("Mon", "Monday"); week.put("Tue", "Tuesday"); week.put("Wed", "Wednesday"); week.put("Thu", "Thursday"); week.put("Fri", "Friday"); System.out.println(week); } } {"Thu":"Thursday","Tue":"Tuesday","Wed":"Wednesday","Fri":"Friday","Mon":"Monday"} package com.tutorialspoint; import org.json.JSONObject; public class JsonDemo { public static void main(String[] arg
🌐
TutorialsPoint
tutorialspoint.com › org_json › org_json_jsonobject.htm
Org.Json - JSONObject Class
package com.tutorialspoint; import org.json.JSONArray; import org.json.JSONObject; public class JsonDemo { public static void main(String[] args) { JSONObject jsonObject = new JSONObject(); jsonObject.put("Name", "Robert"); jsonObject.put("ID", 1); jsonObject.put("Fees", Double.valueOf(1000.21)); jsonObject.put("Active", Boolean.TRUE); jsonObject.put("Other Details", JSONObject.NULL); JSONArray list = new JSONArray(); list.put("foo"); list.put(new Integer(100)); jsonObject.put("list",list); System.out.println(jsonObject); } }
🌐
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.
🌐
DigitalOcean
digitalocean.com › community › tutorials › json-simple-example
json-simple example | DigitalOcean
August 4, 2022 - package com.journaldev.json.write; import java.io.FileWriter; import java.io.IOException; import org.json.simple.JSONArray; import org.json.simple.JSONObject; public class JsonSimpleWriter { @SuppressWarnings("unchecked") public static void main(String[] args) { JSONObject obj = new JSONObject(); obj.put("name", "Pankaj Kumar"); obj.put("age", new Integer(32)); JSONArray cities = new JSONArray(); cities.add("New York"); cities.add("Bangalore"); cities.add("San Francisco"); obj.put("cities", cities); try { FileWriter file = new FileWriter("data.json"); file.write(obj.toJSONString()); file.flush(); file.close(); } catch (IOException e) { e.printStackTrace(); } System.out.print(obj.toJSONString()); } }
🌐
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.
Find elsewhere
🌐
TutorialsPoint
tutorialspoint.com › home › json_simple › json simple quick guide
JSON Simple Quick Guide
March 14, 2013 - JSONValue provide a static method parse() to parse the given json string to return a JSONObject which can then be used to get the values parsed. See the example below. import org.json.simple.JSONArray; import org.json.simple.JSONObject; import ...
Top answer
1 of 4
33

Bit late, but I wanted to share my opinion on this.

I faced this problem recently when I found a Java project with both libraries and they were used at the same time.

I think that org.json is easier to read and to use, for 2 main reasons (for my needs):

  1. JsonObject is immutable. You can't add new key/value pairs to an already existing JsonObject (reference here: javax.json: Add new JsonNumber to existing JsonObject)

  2. It takes a few lines to pretty print a JsonObject or JsonArray, while it only takes 1 line to do it with JSONObject or JSONArray. Example:

    CopyStringWriter sw = new StringWriter();
    Map<String, Object> properties = new HashMap<>();
    properties.put(JsonGenerator.PRETTY_PRINTING, true);
    
    JsonWriterFactory writerFactory = Json.createWriterFactory(properties);
    JsonWriter jsonWriter = writerFactory.createWriter(sw);
    
    jsonWriter.writeObject(jsonObject); //JsonObject created before
    jsonWriter.close();
    String prettyPrintedJSON = sw.toString();
    

That is the code I use to get an indented JSON to write to a file. And with org.json I only need jsonObject.toString(4).

Another difference is the constructors. You will need a JsonObjectBuilder to create a JSON with javax.json. One step more that can be avoided.

I'm sure there are more differences (not sure if it's possible to create a JsonObject from a String) but these are my thoughts.

2 of 4
7

JSONObject, as mentioned, is provided by android's API. JsonObject is specifically used for Java EE development which is essentially for web applications and networking capabilities among other things.

The reason Android does not prepackage JsonObject from Oracle Java EE package is because alot of the things javax can do, are not allowed within android like accessing the internet without permission. This means importing the entire jars files of javax would conflict with Android.

If you plan to build your own backend with Java EE, I would highly suggest using JsonObject over JSONObject. On the other hand, if you know a prebuilt rest service or something similar that supports Android's JSON even better.

🌐
GitHub
gist.github.com › mcSw4p › ab37318dbd394f4b5cc5de5d6d3f6ab3
JSON Simple guide · GitHub
// JSON Simple imports import org.json.simple.JSONArray; import org.json.simple.JSONObject; import org.json.simple.parser.JSONParser; import org.json.simple.parser.ParseException; File jsonFile = new File("/hello.json"); // Do with as you please /* * Simple key value pairs */ JSONParser parser = new JSONParser(); try{ JSONObject jObj = (JSONObject) parser.parse(new FileReader(jsonFile)); } catch (IOException | ParseException e) { e.printStackTrace(); } String value = (String) jObj.get("world"); long delay = (Long) jObj.get("delay"); boolean debug = (Boolean) jObj.get("debug"); /* * JSONArray *
🌐
GeeksforGeeks
geeksforgeeks.org › java › what-is-json-java-org-json
What is JSON-Java (org.json)? - GeeksforGeeks
July 17, 2022 - // Importing JSON simple library import org.json.simple.JSONObject; // Creating a public class public class JsonEncodeExample { // Calling the main method public static void main(String[] args) { // Creating an object of JSON class JSONObject ...
🌐
Miamarti
miamarti.github.io › HorusFramework › javadoc › org › json › simple › JSONObject.html
JSONObject
org.json.simple.JSONObject · All Implemented Interfaces: java.io.Serializable, java.lang.Cloneable, java.util.Map, JSONAware, JSONStreamAware · public class JSONObject extends java.util.HashMap implements java.util.Map, JSONAware, JSONStreamAware · A JSON object.
🌐
JavaMadeSoEasy
javamadesoeasy.com › 2018 › 09 › reading-json-using-jsonsimplejsonobject.html
JavaMadeSoEasy.com (JMSE): Reading JSON using json.simple.JSONObject in java
Create JSON using javax.json.JsonObjectBuilder - Write int, String and Array in java · Create Json using Streaming Model API · Create JSON using json.simple.JSONObject in java · Reading JSON using json.simple.JSONObject in java · Convert java Object to JSON string using com.google.gson.Gson in java ·
🌐
Maven Central
central.sonatype.com › artifact › org.json › json
org.json:json - Maven Central
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. This is a reference implementation. There are a large number of JSON packages in Java.
🌐
Parasoft Forums
forums.parasoft.com › virtualize
Is there a way to import JSONObject in Groovy — Parasoft Forums
August 16, 2021 - I need to convert string to json object using Groovy. But when I try to add the statement import org.json.simple.JSONObject I get the compiler error saying unable to resolve the class.
🌐
Coderanch
coderanch.com › t › 694181 › netbeans › ide › Trouble-JSON-imports
Trouble with JSON imports [Solved] (NetBeans forum at Coderanch)
May 15, 2018 - Yes, it is a jar file not a jar.zip. I can see the problem with the image you posted. In the projects window there is a reference to the json-simple.1.1.jar file under libraries. Mine didn't have that so I right-clicked on libraries and added the jar file as a new library.
🌐
Stleary
stleary.github.io › JSON-java › index.html
Generated Documentation (Untitled)
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