tl  tr
  Home | Tutorials | Articles | Videos | Products | Tools | Search
Interviews | Open Source | Tag Cloud | Follow Us | Bookmark | Contact   
 JSON > GOOGLE GSON > Pretty Print

Pretty Print 

Google-gson is a java library from Google for encoding and decoding JSON text. Get the latest binaries from http://code.google.com/p/google-gson/. The following example shows enabling pretty printing.

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

import java.util.Date;

import com.bethecoder.tutorials.google_gson.common.Student;
import com.google.gson.Gson;
import com.google.gson.GsonBuilder;

public class PrettyPrint {

  /**
   @param args
   */
  public static void main(String[] args) {
    Gson gson = new GsonBuilder().setPrettyPrinting().create();
    Student stud = new Student("Sriram""Kasireddi"2"Singing"new Date(11046));
    System.out.println(gson.toJson(stud));          
  }

}
   

It gives the following output,
{
  "firstName": "Sriram",
  "lastName": "Kasireddi",
  "age": 2,
  "hobby": "Singing",
  "dob": "May 6, 2010 12:00:00 AM"
}



 
  


  
bl  br