serialized() allows you to insert preformatted chunks of JSON (or MessagePack) in a JsonObject or a JsonArray.

Unlike with regular string value, ArduinoJson doesn’t escape the special characters when the string is marked as “serialized.”

You can use this function when you have a part of the document that never changes; you can hard-code this part in the source code, to optimize the serialization.

You can also use this function to insert a part that you cannot recreate with the library.


SerializedValue serialized(const char *value);
SerializedValue serialized(const char *value, size_t size);
SerializedValue serialized(char *value);
SerializedValue serialized(char *value, size_t size);
SerializedValue serialized(const String &value);
SerializedValue serialized(const std::string &value);
SerializedValue serialized(std::string_view value);
SerializedValue serialized(const __FlashStringHelper *value);
SerializedValue serialized(const __FlashStringHelper *value, size_t size);

Return value

serialized() returns a type that is recognized by the library as a raw value that should be serialized as is.


JsonDocument doc;
doc["hello"] = serialized("[\"wor\",\"ld!\"]");
serializeJson(doc, Serial);

will write the following string to the serial port: