Here you can find the source of toJSON(Map
public static String toJSON(Map<String, String> map)
//package com.java2s; //License from project: Apache License import java.util.Map; public class Main { public static String toJSON(Map<String, String> map) { StringBuilder builder = new StringBuilder(); builder.append('{'); boolean first = true; for (Map.Entry<String, String> entry : map.entrySet()) { if (first) first = false;// w w w. j a va 2 s . c o m else builder.append(','); builder.append('"').append(entry.getKey()).append('"').append(':').append('"') .append(entry.getValue().replace("\\", "\\\\").replace("\"", "\\\"")).append('"'); } builder.append('}'); return builder.toString(); } }