tl  tr
  Home | Tutorials | Articles | Videos | Products | Tools | Search
Interviews | Open Source | Tag Cloud | Follow Us | Bookmark | Contact   
 JSON > JSON JAVA > JSON Object

JSON Object 

JSON (JavaScript Object Notation) is a lightweight text-based open standard designed for human-readable data interchange. Douglas Crockford has provided a reference implementation of JSON in Java at http://json.org/ useful for JSON serialization and deserialization. Click here to download the compiled library. The following example shows serializing a simple JSON object.

File Name  :  
com/bethecoder/tutorials/json_java/tests/First.java 
Author  :  Sudhakar KV
Email  :  [email protected]
   
package com.bethecoder.tutorials.json_java.tests;

import org.json.JSONException;
import org.json.JSONObject;

public class First {

  /**
   @param args
   @throws JSONException 
   */
  public static void main(String[] argsthrows JSONException {

    JSONObject obj = new JSONObject();
    obj.put("name""Sriram");
    obj.put("age"2);
    obj.put("hobby""painting");
    
    System.out.println(obj.toString());
    System.out.println(obj.toString(2))//pretty print
  }

}
   

It gives the following output,
{"age":2,"name":"Sriram","hobby":"painting"}

{
  "age": 2,
  "name": "Sriram",
  "hobby": "painting"
}



 
  


  
bl  br