Monday 14, Apr 2025
We are moved to new domain
Click -> www.ehowtonow.com
Saturday, 5 October 2013

How to Create JSON Data using JSONSimple


JSON – JavaScript Object Notation

JSON is a simple data exchange format for read and write data.JSON is the best alternative for XML data.We can create JSON data using Jackson, Google Gson, JSON.simple libraries.

In this tutorials we are going to see how to create json data using JSONSimple jar.

Create project called JSONExample.
Create package called com.javatutorialscorner.json 
Create java class called JSONExample under com.javatutorialscorner.json.

 JSONExample.java

package com.javatutorialscorner.json;

import org.json.simple.JSONArray;
import org.json.simple.JSONObject;

public class JSONExample {

/**
* @param args
*/
public static void main(String[] args) {
// TODO Auto-generated method stub

JSONObject json = new JSONObject();
json.put("name", "www.javatutorialscorner.com");
json.put("Tutorials", "Java & Related Technologies");

JSONArray jsArray = new JSONArray();
jsArray.add("Java");
jsArray.add("J2EE");
jsArray.add("Servlet");
jsArray.add("JSP");
jsArray.add("JSF");
jsArray.add("Struts");
jsArray.add("Spring");
jsArray.add("Hibernate");

json.put("Topics", jsArray);

System.out.println("Json Object " + json);
System.out.println("Json String " + json.toJSONString());
System.out.println("To String " + json.toString());
System.out.println("JSON get " + json.get("Tutorials"));
}

}

Now run the program see the following output in console.


Json Object {"Tutorials":"Java & Related Technologies","name":"www.javatutorialscorner.com","Topics":["Java","J2EE","Servlet","JSP","JSF","Struts","Spring","Hibernate"]}

Json String {"Tutorials":"Java & Related Technologies","name":"www.javatutorialscorner.com","Topics":["Java","J2EE","Servlet","JSP","JSF","Struts","Spring","Hibernate"]}


To String {"Tutorials":"Java & Related Technologies","name":"www.javatutorialscorner.com","Topics":["Java","J2EE","Servlet","JSP","JSF","Struts","Spring","Hibernate"]}


JSON get Java & Related Technologies

Shop and help us

Flipkart Offer Snapdeal offer Amazon.in offer Amazon.com offer

Related Posts:

  • Read JSON Data from FileIn this tutorials we are going to see how to read json data from file using JSONSimple jar. Create project called JSONExample. Create package called com.javatutorialscorner.json  Create java class called JSONExampl… Read More
  • Write JSON using GSON Streaming Gson can read and write JSON as an object model or stream.Gson’s object model uses the same approach as XML DOM and XML pull parser.Gson doesn’t support event-based model like SAX. Streaming Access JsonReader and JsonWriter … Read More
  • How to convert JSON to Java Object using JacksonIn this Tutorials we are going to see how to convert JSON String to Java object using Jackson data binding. 1. Create project called JSONExample. 2. Create package called com.javatutorialscorner.jackson  3. Cr… Read More
  • JSON Tree Model in JacksonIn this Tutorials we are going to see how to read and write JSON Tree model using Jackson JsonNode. The JsonNode is used to read and write tree structured date.It is similar to XML Dom tree. 1. Create project called JSONE… Read More
  • JSON Pretty Print using GSONIn this tutorial we are going to see how to Create Pretty Print JSON String using GSON.1. Create project called JSONExample. 2. Create package called com.javatutorialscorner.gson  3. Create java class called GsonPojo… Read More
  • Blogger Comments
  • Facebook Comments
  • Disqus Comments

0 comments:

Post a Comment

Item Reviewed: How to Create JSON Data using JSONSimple Rating: 5 Reviewed By: eHowToNow