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

Merge JSON Object 

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 merging two JSON Objects.

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

import java.util.Date;

import org.json.simple.JSONObject;

public class MergeJsonObjects {

  /**
   @param args
   */
  public static void main(String[] args) {

    JSONObject jsonObj = new JSONObject();
    jsonObj.put("name""Sriram");
    jsonObj.put("age"2);
    jsonObj.put("hobby""painting");
    
    JSONObject jsonObj2 = new JSONObject();
    jsonObj2.put("hobby""Singing");
    jsonObj2.put("dob"new Date(11046));
    
    jsonObj.putAll(jsonObj2);
    System.out.println(jsonObj);
  }

}
   

It gives the following output,
{"dob":Thu May 06 00:00:00 IST 2010,"age":2,"name":"Sriram","hobby":"Singing"}



 
  


  
bl  br