Description

Allows to insert preformatted chunks of JSON or MessagePack in a JsonObject or a JsonArray. This is useful if you have a part of the document that never changes.

Signatures

serialized(const char *value);
serialized(const char *value, size_t size);
serialized(char *value); // see Remarks
serialized(char *value, size_t size); // see Remarks
serialized(const String &value); // see Remarks
serialized(const std::string &value); // see Remarks
serialized(const __FlashStringHelper *value); // see Remarks
serialized(const __FlashStringHelper *value, size_t size); // see Remarks

Remarks

As usual, ArduinoJson make a copy of the string unless it’s a const char*. For example:

obj["value"] = serialized(String("[1,2,3]")); // makes a copy
// whereas
obj["value"] = serialized("[1,2,3]"); // makes no copy

Example

StaticJsonDocument<200> doc;
JsonObject object = doc.to<JsonObject>();
object["hello"] = serialized("[\"wor\",\"ld!\"]");
serializeJson(object, Serial);

will write the following string to the serial port:

{"hello":["wor","ld!"]}