How to pass JsonObject from ArduinoJson to ESP8266WebServer object? I am learning the ArduinoJson.h library and creating jsonOject:

JsonObject&amp; prepareResponse(JsonBuffer&amp; jsonBuffer) {
  JsonObject&amp; root = jsonBuffer.createObject();
  JsonArray&amp; tempValues = root.createNestedArray("temperature");
  tempValues.add(t);
  JsonArray&amp; humiValues = root.createNestedArray("humidity");
  humiValues.add(h);
  JsonArray&amp; dewpValues = root.createNestedArray("dewpoint");
  dewpValues.add(pfDew);
  JsonArray&amp; EsPvValues = root.createNestedArray("systemv");
  EsPvValues.add(pfVcc / 1000, 3);
  return root;
}


As per the example given here. However since I am using an ESP8266WebServer to create a server object from ESP8266WebServer.h, I cannot pass a JsonObject to server.send(.....).


  no matching function for call to 'ESP8266WebServer::send(int, const
  char [10], ArduinoJson::JsonObject&amp;)'


void outputJson() {
  StaticJsonBuffer&lt;500&gt; jsonBuffer;
  JsonObject&amp; json = prepareResponse(jsonBuffer);
  writeResponse(client, json);
  server.send ( 200, "text/json", json );
}

void writeResponse(WiFiClient&amp; clnt, JsonObject&amp; json) {
  clnt.println("HTTP/1.1 200 OK");
  clnt.println("Content-Type: application/json");
  clnt.println("Access-Control-Allow-Origin: *");
  clnt.println("Connection: close");
  clnt.println();
  json.prettyPrintTo(clnt);
}
As far as I know, the only way is to serialize the JsonObject to a String:

String createJsonResponse() {
  StaticJsonBuffer&lt;500&gt; jsonBuffer;

  JsonObject &amp;root = jsonBuffer.createObject();
  JsonArray &amp;tempValues = root.createNestedArray("temperature");
  tempValues.add(t);
  JsonArray &amp;humiValues = root.createNestedArray("humidity");
  humiValues.add(h);
  JsonArray &amp;dewpValues = root.createNestedArray("dewpoint");
  dewpValues.add(pfDew);
  JsonArray &amp;EsPvValues = root.createNestedArray("systemv");
  EsPvValues.add(pfVcc / 1000, 3);

  String json;
  root.prettyPrintTo(json);
  return json;
}

void outputJson() {
    server.send(200, "text/json", createJsonResponse());
}


By the way, I recommend that you use the ArduinoJson Assistant to compute the size of the JsonBuffer.