
- Java Tutorial
- Java - Home
- Java - Overview
- Java - Environment Setup
- Java - Basic Syntax
- Java - Object & Classes
- Java - Constructors
- Java - Basic Datatypes
- Java - Variable Types
- Java - Modifier Types
- Java - Basic Operators
- Java - Loop Control
- Java - Decision Making
- Java - Numbers
- Java - Characters
- Java - Strings
- Java - Arrays
- Java - Date & Time
- Java - Regular Expressions
- Java - Methods
- Java - Files and I/O
- Java - Exceptions
- Java - Inner classes
- Java Object Oriented
- Java - Inheritance
- Java - Overriding
- Java - Polymorphism
- Java - Abstraction
- Java - Encapsulation
- Java - Interfaces
- Java - Packages
- Java Advanced
- Java - Data Structures
- Java - Collections
- Java - Generics
- Java - Serialization
- Java - Networking
- Java - Sending Email
- Java - Multithreading
- Java - Applet Basics
- Java - Documentation
- Java Useful Resources
- Java - Questions and Answers
- Java - Quick Guide
- Java - Useful Resources
- Java - Discussion
- Java - Examples
Differences between org.simple.json and org.json libraries in Java?
The org.json.simple library allows us to read and write JSON data in Java. In other words, we can encode and decode the JSON object. The org.json.simple package contains important classes like JSONValue, JSONObject, JSONArray, JsonString and JsonNumber. We need to install the json-simple.jar file to execute a JSON program whereas org.json library has classes to parse JSON for Java. It also converts between JSON and XML, HTTP header, Cookies, and CDF. The org.json package contains important classes like JSONObject, JSONTokener, JSONWriter, JSONArray, CDL, Cookie and CookieList. We need to install the json.jar file to execute a JSON program.
Example for org.simple.json package
import org.json.simple.JSONObject; public class SimpleJsonTest { public static void main(String[] args) { JSONObject jsonObj = new JSONObject(); jsonObj.put("empName", "Raja"); jsonObj.put("employeeId", "115"); jsonObj.put("age","30"); System.out.println(jsonObj.toJSONString()); } }
Output
{"empName":"Raja","employeeId":"115","age":"30"}
Example for org.json package
import org.json.*; public class JSONTest { public static void main(String args[]) throws JSONException { String json = "{" + "Name : Jai," + "Age : 25, " + "Salary: 25000.00 " + "}"; JSONObject jsonObj = new JSONObject(json); System.out.println(jsonObj.toString()); } }
Output
{"Salary":25000,"Age":25,"Name":"Jai"}
- Related Articles
- Differences between & and && operators in Java.
- Differences between | and || operators in Java
- Pretty print JSON using org.json library in Java?\n
- Differences between HashMap and Hashtable in Java
- Differences between Collection and Collections in Java?
- Differences between Interface and class in Java
- Differences between ArrayList and LinkedList in Java
- Differences between Java 8 and Java 9?
- Major differences between C# and Java
- Differences between TreeMap, HashMap and LinkedHashMap in Java
- Differences between wait() and sleep() method in Java?
- Differences between wait() and join() methods in Java
- Differences between Lambda Expressions and Closures in Java?
- Differences between abstract class and interface in Java
- Differences between CompletableFuture and Future in Java 9?

Advertisements