How to assign a
This page covers ArduinoJson 5.13.5, consider upgrading to version 6.21.2.
If you try to reassign a
JsonArray or a
JsonObject, you’ll have the following error:
error: use of deleted function 'ArduinoJson::JsonArray& ArduinoJson::JsonArray::operator=(const ArduinoJson::JsonArray&)' error: use of deleted function 'ArduinoJson::JsonObject& ArduinoJson::JsonObject::operator=(const ArduinoJson::JsonObject&)'
JsonObject have their assignment operators private, so you cannot reassign them. Moreover, it’s impossible to reassign a C++ reference.
One solution is to use a pointer instead.
JsonObject* myObject = &root["myObject"].as<JsonObject>();
You can also use a
JsonVariant which will act as a wrapper around the pointer.
JsonVariant myObject = root["myObject"];