title: How to populate JSON from Hashmap data?
body: <p>So I'm working with this data in Java:</p>
  
  <pre><code>HashMap&lt;String, String&gt; currentValues = new HashMap&lt;String, String&gt;();
  String currentID;
  Timestamp currentTime;
  String key;
  </code></pre>
  
  <p>Which I need to convert to this JSON:</p>
  
  <pre><code>{
      "date" : "23098272362",
      "id"   : "123",
      "key"  : "secretkey",
      "data" : [{
               "type"  : "x",
               "value" : "y"
           },{
               "type"  : "a",
               "value" : "b"
           }
       ]
  }
  </code></pre>
  
  <p>But I can't quite work out how.</p>
  
  <p>Currently I'm thinking this is the best approach:</p>
  
  <pre><code>JSONObject dataset = new JSONObject();
  dataset.put("date", currentTime);
  dataset.put("id", currentID);
  dataset.put("key", key);
  
  JSONArray payload = new JSONArray();
  payload.add(dataset);
  </code></pre>
  
  <p>But I'm unsure how I'd do this with the Hashmap. I know it's something like this:</p>
  
  <pre><code>JSONObject data = new JSONObject();
  Iterator it = currentValues.entrySet().iterator();
  while (it.hasNext()) {
      Map.Entry pair = (Map.Entry)it.next();
  
      data.put("type", pair.getKey()) ;
      data.put("value", pair.getValue()) ;
      it.remove(); // avoids a ConcurrentModificationException
  }
  </code></pre>
  
  <p>But the exact syntax and how I'd then add it alongside the other data I can't work out. Any ideas?</p>