Skip to content

passing JsonDocument as a ref #2201

@butaikis

Description

@butaikis

ESP32-WROVER-IE-N8R8
lib version ArduinoJson 7

Hi. Can you tell me if the JsonDocument type can be passed to a function by reference? Or how it is correct in general.

I've noticed a memory leak, and maybe it's because I didn't send the json correctly.

void Core::Add_Sys_JSON(JsonDocument &to) {

  to["device_id"]        = Status.device_id;
  to["chip_id"]          = ESP.getEfuseMac();
  to["model_id"]         = MODEL_ID;
  to["fw_version"]       = FW_VERSION;
  to["mac_eth"]          = GetMAC(ESP_MAC_ETH);
  to["mac_wifi"]         = GetMAC(ESP_MAC_WIFI_STA);
}
void addData(JsonDocument &to_write)
{
json["str"] = "test";
Add_Sys_JSON(to_write);
}
JsonDocument json;
json["id"] = 1;
addData(json);

Metadata

Metadata

Assignees

No one assigned

    Labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions