title: Converting a hashmap into a JSON string
body: <p>I want to convert a hashmap into a json string to send over wire. Here is the code</p>
  
  <pre><code>public static void main(String []args) 
      throws JSONException, JsonParseException, JsonMappingException, IOException {
  
      Map&lt;String,String&gt; varMap = new MyMap&lt;String,String&gt;();
      varMap.put("VAR","123");
      varMap.put("OTHER_VAR","234");
      Gson gson = new GsonBuilder().create();
      String jsonString = gson.toJson(varMap);
  
      JSONObject json = new JSONObject();
      json.put("Variable",jsonString);
      System.out.println("JSON " + json); 
  }
  </code></pre>
  
  <p>The output is </p>
  
  <pre><code>JSON {"Variable":"{\"VAR\":\"123\",\"OTHER_VAR\":\"234\"}"}
  </code></pre>
  
  <p>Which I assume does the right thing, but the examples I've found dont include the backslash in the strng. I understand that the backslash escapes the double quotes and hence none of the string replace method work to replace the backslash.</p>
  
  <p>Is there a trick to get the following output?</p>
  
  <pre><code>JSON {"Variable":{"VAR":"123","OTHER_VAR":"234"}}
  </code></pre>
  
  <p>Can the custom serialization property be used to somehow not add backslashes?</p>