Skip to content

Instantly share code, notes, and snippets.

@okram
Created February 24, 2022 18:40
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save okram/faa1b0951cff1853da2e58c89c762e2c to your computer and use it in GitHub Desktop.
Save okram/faa1b0951cff1853da2e58c89c762e2c to your computer and use it in GitHub Desktop.
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