JsonVariant::measureLength()
⚠️ CAUTION: SLIPPERY FLOOR ⚠️
The Arduino Library Manager installs the ArduinoJson version 6 by default.However, using version 5 is highly recommended because version 6 is still in beta stage.
Open the Arduino Library Manager and make sure that ArduinoJson version 5.13.4 is installed.
Description
Computes the length of the minified JSON document that JsonVariant::printTo()
produces, excluding the null-terminator.
This function is handy to fill the Content-Length
header.
Signature
size_t measureLength() const
Return value
The number of characters that JsonVariant::printTo()
produces, excluding the null-terminator.
Example
// Send headers
client.println("Content-Type: application/json");
client.print("Content-Length: ");
client.println(root.measureLength());
// Terminate headers
client.println();
// Send body
root.printTo(client);