public static void writeMapAsJson(JsonGenerator generator, Map map, String pdxField)
      throws IOException {

    generator.writeStartObject();

    for (final Object o : map.entrySet()) {
      Map.Entry entry = (Map.Entry) o;

      // Iterate over Map and write key-value
      generator.writeFieldName(entry.getKey().toString()); // write Key in a Map
      writeValueAsJson(generator, entry.getValue(), pdxField); // write value in a Map
    }
    generator.writeEndObject();
  }
The JsonWriter class is an utility to write various java types as a JSON string.
<p>

@since GemFire 8.0
geode-web-api/src/main/java/org/apache/geode/rest/internal/web/util/JsonWriter.java