Description

Serializes the JsonDocument to create a prettified JSON document, i.e. a document with spaces and line-breaks between values.

If you want a “minified” JSON document, use serializeJson()

Signatures

size_t serializeJsonPretty(const JsonDocument& doc, char* output, size_t outputSize);
size_t serializeJsonPretty(const JsonDocument& doc, char output[size]);
size_t serializeJsonPretty(const JsonDocument& doc, Print& output);
size_t serializeJsonPretty(const JsonDocument& doc, String& output);
size_t serializeJsonPretty(const JsonDocument& doc, std::string& 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";
object.serializeJsonPretty(Serial);

will write the following string to the serial output:

{
  "hello": "world"
}

See also