devxlogo

Creating a JSON Object Using Java

Creating a JSON Object Using Java

JSON is being widely adapted by the industry for easier transformation of data. Using the json-simple-1.1.1.jar in the classpath will provide you with the basics of JSON and its functionality.

Creating a JSON object is illustrated below.

import org.json.simple.JSONObject;class UsingJson {   public static void main(String args[])   {      JSONObject jsonObject = new JSONObject();      jsonObject.put("id", 10051);      jsonObject.put("name", "Sridhar");      System.out.print("JSONObject : " + jsonObject);   }}/*Expected output:[root@mypc]# java UsingJsonJSONObject : {"name":"Sridhar","id":10051}*/
devxblackblue

About Our Editorial Process

At DevX, we’re dedicated to tech entrepreneurship. Our team closely follows industry shifts, new products, AI breakthroughs, technology trends, and funding announcements. Articles undergo thorough editing to ensure accuracy and clarity, reflecting DevX’s style and supporting entrepreneurs in the tech sphere.

See our full editorial policy.

About Our Journalist