728x90 AdSpace

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.


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();

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

Annamalai Thangaraj

Annamalai is working as Technical Lead in Leading Telecom company with 5+ years experience in Identity and Access Management , Telecom and Networks, BigData, Java, Spring, Struts, Hibernate, AngularJS, and Enterprise Web Application Development.

Website: Java Tutorials Corner

Shop and help us

Flipkart Offer Snapdeal offer Amazon.in offer Amazon.com offer
  • Blogger Comments
  • Facebook Comments
  • Disqus Comments


Post a Comment

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