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

This function treats String and std::string as streams: it doesn’t replace the content, it appends to the end.

Return value

The number of characters written.

Configuration

serializeJsonPretty() can be configured with the following settings:

Example

StaticJsonDocument<200> doc;
doc["hello"] = "world";
serializeJsonPretty(doc, Serial);

will write the following string to the serial output:

{
  "hello": "world"
}

See also