API Esp8266 problems

Hi, I have another question…

I have been trying to study this code to know what it does exactly but I cannot find specific information about the operation of this code or the libraries.


#include <ESP8266WiFi.h>
#include <ESP8266HTTPClient.h>
#include <ArduinoJson.h>

const char* ssid = "Internet";
const char* password = "Password";

void setup() 
  WiFi.begin(ssid, password);

  while (WiFi.status() != WL_CONNECTED) 

void loop() 
  if (WiFi.status() == WL_CONNECTED) 
    HTTPClient http; //Object of class HTTPClient
    int httpCode = http.GET();

    if (httpCode > 0) 
      const size_t bufferSize = JSON_OBJECT_SIZE(2) + JSON_OBJECT_SIZE(3) + JSON_OBJECT_SIZE(5) + JSON_OBJECT_SIZE(8) + 370;
      DynamicJsonBuffer jsonBuffer(bufferSize);
      JsonObject& root = jsonBuffer.parseObject(http.getString());
      int id = root["id"]; 
      const char* name = root["name"];
      const char* username = root["username"]; 
      const char* email = root["email"]; 

    http.end(); //Close connection

Serial Print:

Name:Leanne Graham

I would like to know what each part does, especially this:
const size_t bufferSize = JSON_OBJECT_SIZE(2) + JSON_OBJECT_SIZE(3) + JSON_OBJECT_SIZE(5) + JSON_OBJECT_SIZE( 8 ) + 370;
DynamicJsonBuffer jsonBuffer(bufferSize);
JsonObject& root = jsonBuffer.parseObject(http.getString());

I need to know this information because I want to put an API from wikipedia, but I think the problem is that it is too heavy to store in RAM, so I would be saving it in parts in an SD

API I want to use: https://en.wikipedia.org/w/api.php?action=query&prop=revisions&rvprop=content&format=json&titles=car

Its possible?

buffersize reserves enough buffer for your json you expect.

See the documentation of ArduinoJson about what's needed.
There is even an Assistant to generate these lines of code:

If you put in your JSON you will get something like

const size_t capacity = 2*JSON_ARRAY_SIZE(1) + 3*JSON_OBJECT_SIZE(1) + 3*JSON_OBJECT_SIZE(2) + 2*JSON_OBJECT_SIZE(3) + JSON_OBJECT_SIZE(4) + 78700;
DynamicJsonDocument doc(capacity);