Need help with Arduino NODEMCU HTTP request values are nulll after parsing with json

Hey folks,

I'm encountering an issue with an HTTP GET request to Firestore. After performing deserializeJson, the values I receive are sometimes null and other times valid, which is proving to be inconsistent.

Can anyone guide me on what might be going wrong?

bool readScheduleCollection() {
  String url = firestore_base_url + "schedules?key=" + api_key;
  client.setInsecure();               // Use this to disable SSL certificate verification (not recommended for production)
  client.setBufferSizes(2048, 2048);  // Increase buffer sizes for SSL
  http.begin(client, url);            // Updated to use WiFiClientSecure
  int httpCode = http.GET();

  if (httpCode == 200) {
    String payload = http.getString();
    Serial.println("Payload received:");
    Serial.println(payload);

    StaticJsonDocument<8192> doc;  // Increase size as needed
    DeserializationError error = deserializeJson(doc, payload);


    Serial.println("Successfully read schedule collection:");
    JsonArray documents = doc["documents"].as<JsonArray>();
    String jsonArrayString;
    serializeJson(documents, jsonArrayString);
    Serial.println(jsonArrayString);
    CustomSerial.println("SCHEDULES," + jsonArrayString);


    return true;
  } else {
    Serial.println("Failed to read schedule collection");
    Serial.println("Error: " + String(httpCode));
    return false;
  }

  http.end();
}

Here's the output from th HTTP request

Here's the output after parsing it with json

so you never get a JSON error but sometimes the values are empty?

can you print the JSON you get in payload and check if the values are always in there? (when the deserializeJson() does not give you values )

This topic was automatically closed 180 days after the last reply. New replies are no longer allowed.