Skip to content

Instantly share code, notes, and snippets.

@okram
Created Feb 24, 2022
Embed
What would you like to do?
static JsonObject toJson(const byte *payload, const uint32_t length) {
char *json = (char *)malloc(length);
memcpy(json, payload, length);
if (json[0] == NULL) {
json = json + 2;
}
json[length - 1] = NULL;
StaticJsonDocument<256> doc;
DeserializationError error = deserializeJson(doc, json);
if (error) {
Serial.println(error.c_str());
return JsonObject();
} else
return doc.to<JsonObject>();
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment