@Override
  public synchronized String toString() {
    Writer writer = new StringWriter();
    try {
      boolean addComma = false;
      writer.write('{');
      for (Map.Entry<String, List<Object>> entry : map.entrySet()) {
        if (addComma) {
          writer.write(',');
        }

        // Keys are always of type String, in order to keep backward compatibility we need to
        // manually serialize them without type.
        writer.write("\"");
        writer.write(entry.getKey());
        writer.write("\"");
        writer.write(':');
        writeList(writer, entry.getValue());
        addComma = true;
      }
      writer.write('}');

      return writer.toString();
    } catch (Exception e) {
      e.printStackTrace();
    }

    return null;
  }
After instantiating a formatter add the objects you want to be formatted using this method.
Typically this will be add("result", queryResult)
geode-core/src/main/java/org/apache/geode/management/internal/json/QueryResultFormatter.java