I'm trying to effectively allocate a doc's size, based on the size of the file saved in flash of ESP8266. Is there a way?
For example: file.size() X 1.5
I'm trying to effectively allocate a doc's size, based on the size of the file saved in flash of ESP8266. Is there a way?
For example: file.size() X 1.5
There is unfortunately no way to predict the size of the JsonDocument from the file size alone.
As a workaround, I suggest that you allocate a very large memory pool and shrink it after deserialization; like so:
DynamicJsonDocument doc(ESP.getMaxAllocHeap());
deserializeJson(doc, file);
doc.shrinkToFit();
Indeed, this program consumes more memory than strictly required, but only for a fraction of a second.
See also:
StaticJsonDocument is not an option.