public static void writeListAsJson(JsonGenerator generator, Map map, String name,
      String fieldName) throws IOException {

    generator.writeStartObject();
    generator.writeFieldName(name);

    // introspect the Map and write its value into desired format
    generator.writeStartArray();
    for (final Object o : map.entrySet()) {

      Map.Entry entry = (Map.Entry) o;
      generator.writeStartObject();
      // Iterate over Map and write key-value
      generator.writeFieldName(fieldName);
      generator.writeString(entry.getKey().toString());

      writeValueAsJson(generator, entry.getValue(), name);
      generator.writeEndObject();
    }

    generator.writeEndArray();
    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