JsonVariant::shallowCopy()
Description
JsonVariant::shallowCopy()
includes the specified value without making a copy.
In a way, it’s the opposite of JsonVariant::set()
, which makes a deep copy of the value.
JsonVariant::shallowCopy()
allows you to embed a JsonDocument
inside another without increasing the memory consumption.
This feature was added in ArduinoJson 6.20.0
Signatures
void shallowCopy(JsonVariantConst variant) const;
Arguments
variant
: the variant to link to.
Since JsonArray
, JsonDocument
, JsonObject
, and JsonVariant
convert to JsonVariantConst
, you can pass any of these classes to JsonVariant::shallowCopy()
.
Example
void sendJsonRpcRequest(const char* method, JsonVariantConst params) {
StaticJsonDocument<64> doc;
doc["jsonrpc"] = "2.0";
doc["id"] = 1;
doc["method"] = method;
doc["params"].shallowCopy(params);
serializeJson(doc, client);
}