title: Java: Append JSON Object to a JSON Object
body: <p>I want to store chat history in a JSON Object, one object for each conversation, within this object i want to have an Array with all the messages. </p>
  
  <p>Like this:</p>
  
  <pre><code>{"Channel_123":[
             {"from":"john","to":"bill", "msg":"Hello", "time":"09:57"},
             {"from":"bill","to":"john", "msg":"Hey John", "time":"09:58"}
           ]
  }, {"Channel_234":[
             {"from":"bob","to":"judy", "msg":"Hello", "time":"10:37"},
             {"from":"judy","to":"bob", "msg":"Hey!", "time":"10:38"}
           ]
  }
  </code></pre>
  
  <p>My current method looks like this: (the string <code>channel</code> contains the conversation id illustrated above with <code>Channel_234</code></p>
  
  <pre><code>JSONObject obj = new JSONObject();
  JSONObject msgObj = new JSONObject();
  
  public void addMessage(String from, String to, String msg, String time, String channel) {
  
      try {
          msgObj.put("from", from);
          msgObj.put("to", to);
          msgObj.put("msg", msg);
          msgObj.put("time", time);
  
  
          obj.put(channel, array);
  
      } catch (Exception ex) {
          System.out.println(ex.getStackTrace());
          logger.log(Level.SEVERE, "Exception: ", ex);
      }
  
      System.out.println(obj);
  }
  </code></pre>
  
  <p>But for some reason the method is not appending to the object it is overwriting what was previously there.</p>
  
  <p>Any ideas?</p>
  
  <p><strong>EDIT</strong></p>
  
  <p>I am using the simple json lib: <code>json-simple-1.1.1.jar</code></p>