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

JSON Writer 

JSON Simple is a java library for encoding and decoding JSON text. Get the latest binaries from http://code.google.com/p/json-simple/. The following example shows serializing a simple JSON Object to a file.

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

import java.io.FileWriter;
import java.io.IOException;

import org.json.simple.JSONObject;

public class JsonWriter {

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

    JSONObject obj = new JSONObject();
    obj.put("name""Sriram");
    obj.put("age"2);
    obj.put("hobby""painting");
    
    FileWriter jsonWriter = new FileWriter("json.txt");
    obj.writeJSONString(jsonWriter);
    jsonWriter.close();
  }

}
   

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



 
  


  
bl  br