I found an issue on ESP32 that I was able to fix it like that:
const char * jsonString = cJSON_PrintUnformatted(doc); //... cJSON_free((void*)jsonString); cJSON_Delete(root);