Serializes the JsonVariant to create a minified JSON document.

If you want a pretty JSON with spaces and line breaks, use JsonVariant::prettyPrintTo()


size_t printTo(char* buffer, size_t size) const;
size_t printTo(char buffer[size]) const;
size_t printTo(Print &) const;
size_t printTo(String &) const;
size_t printTo(std::string &) const;


The destination where the JSON document should be written. It can be either:

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 bytes written.


StaticJsonBuffer<200> jsonBuffer;
JsonObject& object = jsonBuffer.createObject();
object["hello"] = "world";

JsonVariant variant = object;

will write the following string to the serial port:


See also