JsonVariant::link() 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::link() allows you to embed a JsonDocument inside another without increasing the memory consumption. One could also describe this feature as “shallow copy.”

The embedded document appears as read-only from the point of view of the parent document. In other words, if doc["link"] points to another document, you cannot alter the value of doc["link"]["value"].

This feature was added in ArduinoJson 6.20.0


void link(JsonVariantConst variant) const;


variant: the variant to link to.

Since JsonArray, JsonDocument, JsonObject, and JsonVariant convert to JsonVariantConst, you can pass any of these classes to JsonVariant::link().


void sendJsonRpcRequest(const char* method, JsonVariantConst params) {
  StaticJsonDocument<64> doc;
  doc["jsonrpc"] = "2.0";
  doc["id"] = 1;
  doc["method"] = method;
  serializeJson(doc, client);

See also