code: public static JSONObject mapToJsonObject(Map<String, Object> map)
      {
          JSONObject jsonObj = new JSONObject();
          
          try {
              for (String key : map.keySet())
              {
                  Object value = map.get(key);
                  if (value instanceof Map)
                      jsonObj.put(key, AjaxProxyTask.mapToJsonObject((Map)value));
                  else
                      jsonObj.put(key, value);
              }
          } catch (JSONException e) {
              e.printStackTrace();
          }
          
          return jsonObj;
      }
docs: Utility to convert a map to a JSON object.
  @param map
  @return