ArduinoJson: F.A.Q

How to assign a JsonArray or JsonObject?

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&)'

Indeed, you cannot reassign a JsonObject&.

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"];


Fork me on GitHub