public static String encode(Map<String, ?> map) {
        StringBuilder b = new StringBuilder("{");
        for (Map.Entry<String,?> entry : map.entrySet()) {
            b.append("\"").append(escape(entry.getKey())).append("\":");
            if (entry.getValue() instanceof String)
                b.append("\"").append(escape(entry.getValue().toString())).append("\"");
            else // Number, or some other object which returns JSON
                b.append(entry.getValue());
            b.append(",");
        }
        if (b.length()>1)
            b.setLength(b.length()-1); // remove last comma
        b.append("}");
        return b.toString();
    }
Outputs a map as a JSON 'object' string, provided that the map values
are either
<ul>
<li>String
<li>Number
<li>Any object whose toString returns JSON
</ul>
vespajlib/src/main/java/com/yahoo/text/JSON.java