Description

Serializes the JsonDocument to create a minified JSON document, i.e. a document without spaces or line break between values.

If you want a prettified JSON document, use serializeJsonPretty()

Signatures

serializeJson(const JsonDocument& doc, char* output, size_t outputSize);
serializeJson(const JsonDocument& doc, char output[size]);
serializeJson(const JsonDocument& doc, Print& output);
serializeJson(const JsonDocument& doc, String& output);
serializeJson(const JsonDocument& doc, std::string& output);
serializeJson(const JsonDocument& doc, std::ostream& output);

Arguments

doc: the JsonDocument to serialize (in fact, you can also use a JsonArray, a JsonObject, or a JsonVariant)

output: the destination where the JSON document should be written

outputSize: the capacity of the destination buffer

Because output can be any implementation of Print, you can uses instances like Serial, EthernetClient, WifiClient

Return value

The number of bytes written.

Example

StaticJsonDocument<200> doc;
JsonObject object = doc.to<JsonObject>();
object["hello"] = "world";
serializeJson(object, Serial);

will write the following string to the serial port:

{"hello":"world"}

See also