Skip to content

Instantly share code, notes, and snippets.

@alexastrum
Last active July 29, 2020 21:37
Show Gist options
  • Save alexastrum/2e2fb3e94f7701938fe8bb677e4973ab to your computer and use it in GitHub Desktop.
Save alexastrum/2e2fb3e94f7701938fe8bb677e4973ab to your computer and use it in GitHub Desktop.
DynamicJsonDocument toJsonDocument(String str, int size = 0) {
if (size == 0) {
size = JSON_OBJECT_SIZE(1) + str.length();
}
DynamicJsonDocument jsonDoc(str.length() * 2);
DeserializationError error = deserializeJson(jsonDoc, str);
if (error) {
displayError("JSON " + String(error.c_str()) + ": " + str);
jsonDoc.clear();
}
return jsonDoc;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment