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.
package com.bethecoder.tutorials.json_simple.tests; import org.json.simple.JSONObject; public class First { /** * @param args */ public static void main(String[] args) { JSONObject obj = new JSONObject(); obj.put("name", "Sriram"); obj.put("age", 2); obj.put("hobby", "painting"); System.out.println(obj); } }
{"age":2,"name":"Sriram","hobby":"painting"}