user27953: I am trying to figure out how ArduinoJson capacity can be calculated, therefore I came by the Assistant web application developed by the developer of the library https://arduinojson.org/v6/assistant/
Here what I do not understand is, why when I use either of the following two JSON strings, the helper shows me the same capacity? I would expect that the longer JSON values will result in a bigger capacity, but this does not seem to be the case.
{
  "wifi": {
    "ssid": "S",
    "password": "P",
    "hostname": "H"
  },
  "administration": {
    "username": "U",
    "password": "P"
  }
}

{
  "wifi": {
    "ssid": "SSSSSSSSSSSSSSSSSSSSSSSSSSS",
    "password": "PPPPPPPPPPPPPPPPPPPPPPPPPP",
    "hostname": "HHHHHHHHHHHHHHHHHHHHHHHHHHHH"
  },
  "administration": {
    "username": "UUUUUUUUUUUUUUUUUUUUUUUUUUUUUU",
    "password": "PPPPPPPPPPPPPPPPPPPPPPPPPPPPPP"
  }
}

I am trying to calculate the capacity using the assistant using the following configuration:
ESP8266 / Deserialize / char*
Could you anyone explain this to me? Apparently I understand the "reason" behind the capacity wrong?

user27953: I found what the real problem is. In the assistant tool, when choosing const char * as the input type, it shows that the size of the string is 0, which is wrong according to the documentation of the library.
https://arduinojson.org/v6/api/json/deserializejson/

// writable input => zero-copy
DeserializationError deserializeJson(JsonDocument& doc, char* input);
// read-only input => duplication
DeserializationError deserializeJson(JsonDocument& doc, const char* input);

The assistant, if I see correctly, does not distinguish between these two cases, and thus gives the wrong capacity for this const case.
Accordingly, in const char * it is not enough to only take the size of the structure, but also we need to consider the data stored in it.
According to the documentation, the reason why const char * cannot be a zero-copy is:

3.9.2 Duplication is required
As we saw in the previous section, in the zero-copy mode, ArduinoJson stores pointers
pointing inside the input buffer. We saw that it has to replace some characters of the
input with null-terminators.
With a read-only input, ArduinoJson cannot do that anymore, so it needs to make copies
of "hip" and "hop". Where do you think the copies would go? In the JsonDocument, of
course!

UPDATE
After reporting this bug (see the link below), it has been quickly fixed!
https://github.com/bblanchon/ArduinoJson/issues/1488

user7508: If you look at the details of the numbers reported, you should see:
Data structures     112
Strings             0
Total (minimum)     112
Total (recommended) 128

As you see, there are exactly zero bytes allocated for the strings. This
means that the library does not copy the strings, and instead references
them from the character array you provide as an input.
If you instead configure the library for Stream input, it will have to
store the strings, and the capacity is then very different for these two
documents.

27953: <p>I am trying to figure out how <code>ArduinoJson</code> capacity can be calculated, therefore I came by the Assistant web application developed by the developer of the library <a href="https://arduinojson.org/v6/assistant/" rel="nofollow noreferrer">https://arduinojson.org/v6/assistant/</a></p>
<p>Here what I do not understand is, why when I use either of the following two JSON strings, the helper shows me the same capacity? I would expect that the longer JSON values will result in a bigger capacity, but this does not seem to be the case.</p>
<pre><code>{
  &quot;wifi&quot;: {
    &quot;ssid&quot;: &quot;S&quot;,
    &quot;password&quot;: &quot;P&quot;,
    &quot;hostname&quot;: &quot;H&quot;
  },
  &quot;administration&quot;: {
    &quot;username&quot;: &quot;U&quot;,
    &quot;password&quot;: &quot;P&quot;
  }
}

{
  &quot;wifi&quot;: {
    &quot;ssid&quot;: &quot;SSSSSSSSSSSSSSSSSSSSSSSSSSS&quot;,
    &quot;password&quot;: &quot;PPPPPPPPPPPPPPPPPPPPPPPPPP&quot;,
    &quot;hostname&quot;: &quot;HHHHHHHHHHHHHHHHHHHHHHHHHHHH&quot;
  },
  &quot;administration&quot;: {
    &quot;username&quot;: &quot;UUUUUUUUUUUUUUUUUUUUUUUUUUUUUU&quot;,
    &quot;password&quot;: &quot;PPPPPPPPPPPPPPPPPPPPPPPPPPPPPP&quot;
  }
}
</code></pre>
<p>I am trying to calculate the capacity using the assistant using the following configuration:</p>
<p><em>ESP8266 / <strong>Deserialize</strong> / char</em>*</p>
<p>Could you anyone explain this to me? Apparently I understand the &quot;reason&quot; behind the capacity wrong?</p>
 27953: <p>I found what the real problem is. In the assistant tool, when choosing <code>const char *</code> as the input type, it shows that the size of the string is 0, which is <strong>wrong</strong> according to the documentation of the library.</p>
<p><a href="https://arduinojson.org/v6/api/json/deserializejson/" rel="nofollow noreferrer">https://arduinojson.org/v6/api/json/deserializejson/</a></p>
<blockquote>
<p>// writable input =&gt; zero-copy<br />
DeserializationError deserializeJson(JsonDocument&amp; doc, char* input);<br />
// read-only input =&gt; duplication<br />
DeserializationError deserializeJson(JsonDocument&amp; doc, const char* input);</p>
</blockquote>
<p>The assistant, if I see correctly, does <strong>not</strong> distinguish between these two cases, and thus gives the wrong capacity for this <code>const</code> case.</p>
<p>Accordingly, <strong>in <code>const char *</code> it is not enough to only take the size of the structure, but also we need to consider the data stored in it.</strong></p>
<p>According to <a href="https://arduinojson.org/v6/doc/deserialization/" rel="nofollow noreferrer">the documentation</a>, the reason why <code>const char *</code> cannot be a zero-copy is:</p>
<blockquote>
<p>3.9.2 Duplication is required
As we saw in the previous section, in the zero-copy mode, ArduinoJson stores pointers
pointing inside the input buffer. We saw that it has to replace some characters of the
input with null-terminators.
With a read-only input, ArduinoJson cannot do that anymore, so it needs to make copies
of &quot;hip&quot; and &quot;hop&quot;. Where do you think the copies would go? In the JsonDocument, of
course!</p>
</blockquote>
<h3>UPDATE</h3>
<p>After reporting this bug (see the link below), it has been quickly fixed!</p>
<p><a href="https://github.com/bblanchon/ArduinoJson/issues/1488" rel="nofollow noreferrer">https://github.com/bblanchon/ArduinoJson/issues/1488</a></p>
 7508: <p>If you look at the details of the numbers reported, you should see:</p>
<pre><code>Data structures     112
Strings             0
Total (minimum)     112
Total (recommended) 128
</code></pre>
<p>As you see, there are exactly zero bytes allocated for the strings. This
means that the library does not copy the strings, and instead references
them from the character array you provide as an input.</p>
<p>If you instead configure the library for <code>Stream</code> input, it will have to
store the strings, and the capacity is then very different for these two
documents.</p>
