HTTPS get JSON remove unwanted data

Hello I try to get data from a json response thats on a https source:

JSON data

{
    "Status": 1,
    "New Saldo": 2.5,
    "Old Saldo": 4.5
}

I get a response and can print the loaded data in payload.

Only for some reason the serial debug gives:

[HTTPS] Received payload: <pre>{
    "Status": 1,
    "New Saldo": 2.5,
    "Old Saldo": 4.5
}</pre>

How to get rid of the

 tag, because when I use the ArduinoJSON plugin I get a deserializeJson() failed: InvalidInput

Arduino code:

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

void setup() {
  Serial.begin(115200);
  Serial.println(F("\n\r* * * ESP BOOT * * *"));
  Serial.println(F("WiFi begin!"));
  WiFi.mode(WIFI_STA);
  WiFi.begin("SPIKIE", "testtest");

  while (WiFi.status() != WL_CONNECTED) {
    delay(500);
    Serial.print(".");
  }

  Serial.println(F("\n\rWiFi connected!"));
}

void getpr24h() {
  std::unique_ptr<BearSSL::WiFiClientSecure>client(new BearSSL::WiFiClientSecure);
  client->setInsecure();
  HTTPClient https;

  if (https.begin(*client, "https://www.**** URL **** ")) {  // HTTPS
    Serial.println("[HTTPS] GET...");
    int httpCode = https.GET();

    // httpCode will be negative on error
    if (httpCode > 0) {
      // HTTP header has been send and Server response header has been handled
      Serial.printf("[HTTPS] GET... code: %d\n", httpCode);
      // file found at server?
      if (httpCode == HTTP_CODE_OK) {
        String payload = https.getString();
        Serial.println(String("[HTTPS] Received payload: ") + payload);

        Serial.println("-------------------------------");
        
        StaticJsonDocument<256> doc;

        //payload = "{\"hello\":\"world\"}";
        payload = "<pre>{\"Status\": \"1\",\"New Saldo\": 2.5,\"Old Saldo\": 4.5}</pre>";

        
        DeserializationError error = deserializeJson(doc, payload);
        
        if (error) {
          Serial.print(F("deserializeJson() failed: "));
          Serial.println(error.f_str());
          return;
        }
        
        const char* text = doc["Status"];
        
        Serial.println(text);
   
      }
    } else {
      Serial.printf("[HTTPS] GET... failed, error: %s\n\r", https.errorToString(httpCode).c_str());
    }

    https.end();
  } else {
    Serial.printf("[HTTPS] Unable to connect\n\r");
  }
}

void loop() {
  getpr24h();
  Serial.println("Wait 20s before next round to not get banned on API server...");
  delay(20000);
}

I think i need to get rid of the header data, only I can not figure out how to.

Already fixed, the json file I create was wrong code markup.

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