user48730: 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

user3430: 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:

How to determine the capacity of the JsonDocument?
BasicJsonDocument::shrinkToFit()


48730: <p>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?</p>
<p>For example: <code>file.size()</code> X 1.5</p>
 3430: <p>There is unfortunately no way to predict the size of the <a href="https://arduinojson.org/v6/api/jsondocument/" rel="nofollow noreferrer"><code>JsonDocument</code></a> from the file size alone.</p>
<p>As a workaround, I suggest that you allocate a very large memory pool and shrink  it after deserialization; like so:</p>
<pre class="lang-cpp prettyprint-override"><code>DynamicJsonDocument doc(ESP.getMaxAllocHeap());
deserializeJson(doc, file);
doc.shrinkToFit();
</code></pre>
<p>Indeed, this program consumes more memory than strictly required, but only for a fraction of a second.</p>
<p>See also:</p>
<ul>
<li><a href="https://arduinojson.org/v6/how-to/determine-the-capacity-of-the-jsondocument/" rel="nofollow noreferrer">How to determine the capacity of the JsonDocument?</a></li>
<li><a href="https://arduinojson.org/v6/api/basicjsondocument/shrinktofit/" rel="nofollow noreferrer">BasicJsonDocument::shrinkToFit()</a></li>
</ul>
