string()

string(value) → string

Converts numbers and objects to strings for logging and transmission.

Serialises a value to a string. Objects are converted to their JSON representation — this is the standard way to prepare a payload for http.req, mqtt.publish, udp.send or sd.append, and to make objects printable.

The inverse for JSON text is JSON.parse().

Arguments

NameTypeRequiredDefaultDescription
value any yes Number, object or other value to serialise.

Returns

string String / JSON representation of the value.

Example

let payload = { batteryVoltage: 14.3, uptime: now() };
http.req("http://myserver.com/url", string(payload), 1000, false);