Easy learning with example program codes

How to use JSON object in java?

Let us discuss how to use JSON object in java with the help of below example.


1. Include JSON jar in classpath.
2. Create JSONObject object.
3. Add data to JSONObject.
3. Process the object.


import net.sf.json.JSONObject;
 * This class show use JSON object in java.
 * @author codesjava
public class JSONTest {
	public static void main(String args[]){
	    //Create JSON object
	    JSONObject obj = new JSONObject();
	    //Add data to JSON object.
	    obj.put("name", "Bharat");
	    obj.put("rollNo", "MCA/07/05");
	    obj.put("id", new Integer(50));	    
	    //Print JSON object.



Download this example.
Next Topic: How to parse json in java with example?
Previous Topic: How to access json object array in javascript?

Related Topics:

How to build java project using ant in eclipse?
JAXB marshalling – convert java object to xml example.
How to create pdf file in java using iText jar?
Generics class example.
OGNL in struts 2.
Hibernate One-to-One Mapping using xml.
Send inline image in email using JavaMail API.
Quartz 2 JobListener example.


Industrial Training

We offers Placement Oriented Training on Java, Spring, JSF, Hibernate, PHP, AngularJS, Angular 4, PLSQL, Oracle BI Publisher etc. We also provides Online training, please mail us at


We also provides the Development services for Website Development , Java Development, PHP Development, Android App Development etc. You can contact us on

Copyright © 2019 CodesJava Protection Status SiteMap Reference: Java Wiki