user48730: Parameter file containing MQTT topics as shown below, is read into StaticJsonDocument<1250> DOC variable.
Size of some groups may differ between MCU's, for example sub_topics_win may contain more topics, if MCU is 8 relay unit. For that I need the flexibility to read a specific topic that can differ in size.
What is the rifht way to do it?
{
    "pub_gen_topics": [
        "myHome/Messages",
        "myHome/log",
        "myHome/debug"
    ],
    "pub_topics": [
        "myHome/Cont_A/Avail",
        "myHome/Cont_A/State"
    ],
    "sub_topics": [
        "myHome/Cont_A",
        "myHome/All",
        "myHome/lockdown"
    ],
    "sub_topics_win": [
        "myHome/Windows/gFloor/TwinWindow",
        "myHome/Windows/gFloor/Pergola"
    ],
    "sub_topics_SW": [
        "myHome/Light/int/gFloor/SalAmbient1",
        "myHome/Light/int/gFloor/SalAmbient2",
        "myHome/Light/int/gFloor/Lobby",
        "myHome/Light/int/gFloor/Corridor"
    ],
    "sub_topics_win_g": [
        "myHome/Windows",
        "myHome/Windows/gFloor"
    ],
    "sub_topics_SW_g": [
        "myHome/Light",
        "myHome/Light/int",
        "myHome/Light/int/gFloor/"
    ],
    "ver": 0.1
}


user3430: If your question is How can I read each element of an array when I don't know its size?, then simply use a for-loop, like so:
JsonArray sub_topics_win = doc["sub_topics_win"];

for (const char* topic : pub_gen_topics) {
  Serial.println(topic);
}

See also: JsonArray::begin() / end(), JsonArray::size().

48730: <p>Parameter file containing MQTT topics as shown below, is read into <code>StaticJsonDocument&lt;1250&gt; DOC</code> variable.</p>
<p>Size of some groups may differ between MCU's, for example <code>sub_topics_win</code> may contain more topics, if MCU is 8 relay unit. For that I need the flexibility to read a specific topic that can differ in size.</p>
<p>What is the rifht way to do it?</p>
<pre><code>{
    &quot;pub_gen_topics&quot;: [
        &quot;myHome/Messages&quot;,
        &quot;myHome/log&quot;,
        &quot;myHome/debug&quot;
    ],
    &quot;pub_topics&quot;: [
        &quot;myHome/Cont_A/Avail&quot;,
        &quot;myHome/Cont_A/State&quot;
    ],
    &quot;sub_topics&quot;: [
        &quot;myHome/Cont_A&quot;,
        &quot;myHome/All&quot;,
        &quot;myHome/lockdown&quot;
    ],
    &quot;sub_topics_win&quot;: [
        &quot;myHome/Windows/gFloor/TwinWindow&quot;,
        &quot;myHome/Windows/gFloor/Pergola&quot;
    ],
    &quot;sub_topics_SW&quot;: [
        &quot;myHome/Light/int/gFloor/SalAmbient1&quot;,
        &quot;myHome/Light/int/gFloor/SalAmbient2&quot;,
        &quot;myHome/Light/int/gFloor/Lobby&quot;,
        &quot;myHome/Light/int/gFloor/Corridor&quot;
    ],
    &quot;sub_topics_win_g&quot;: [
        &quot;myHome/Windows&quot;,
        &quot;myHome/Windows/gFloor&quot;
    ],
    &quot;sub_topics_SW_g&quot;: [
        &quot;myHome/Light&quot;,
        &quot;myHome/Light/int&quot;,
        &quot;myHome/Light/int/gFloor/&quot;
    ],
    &quot;ver&quot;: 0.1
}
</code></pre>
 3430: <p>If your question is <em>How can I read each element of an array when I don't know its size?</em>, then simply use a for-loop, like so:</p>
<pre class="lang-cpp prettyprint-override"><code>JsonArray sub_topics_win = doc[&quot;sub_topics_win&quot;];

for (const char* topic : pub_gen_topics) {
  Serial.println(topic);
}
</code></pre>
<p>See also: <a href="https://arduinojson.org/v6/api/jsonarray/begin_end/" rel="nofollow noreferrer">JsonArray::begin() / end()</a>, <a href="https://arduinojson.org/v6/api/jsonarray/size/" rel="nofollow noreferrer">JsonArray::size()</a>.</p>
