user48730: I'm using RF24 library to send messages between 2 MCU's : 1) ESP8266 (no Wifi, same code can be compiled to any Arduino board) 2) pro-Micro.
Message is sent in JSON format, while using ArduinoJSON library to serialize and deserialize messages.
Altough entire code works as expected, I get an error in "RFread" function, which _readmsg array loses its content after using deserializeJson.
Attached below  relevant part of "RFread" function. Explanations in code below. Please notice "Mark [X]" in code and Serial output:
char _readmsg[32];                                <---- Storing input in this array
    char t2[32];                                  <---- variable to clone value
    radio.read(&_readmsg, sizeof(_readmsg));      <---- getting RF input and store it in `_readmsg`
    strcpy(t2, _readmsg);                         <---- cloning, part of error seeking

    Serial.print("first: ");                      <---- printing initial value stored. OK. marked [A] in Serial output
    Serial.println(_readmsg);
    Serial.print("duplicate: ");                  <---- printing clone. OK. marked [B] in Serial output
    Serial.println(t2);
    
    if (key != nullptr)                           <--- check if "msg" key was sent in message
    {
      StaticJsonDocument<80> DOC;
      deserializeJson(DOC, _readmsg);             <---- **error beyond this point**
      Serial.print("second: ");
      Serial.println(_readmsg);                   <---- printing wrong value. marked [C] in Serial output

      if (DOC.containsKey(key))
      {
        const char *outmsg = DOC[key];
        if (out != nullptr)
        {
          strcpy(out, outmsg);
          return true;
        }
      }
      else
      {
        Serial.print("third: ");               
        Serial.println(_readmsg);              <---- still error. marked [D] in Serial output
        Serial.print("duplicate2: ");
        Serial.println(t2);                    <---- clone variable is OK. marked [E] in Serial output
        strcpy(out, t2); // if key not present, return entire message
        return 0;
      }

and in Serial port:
message sent OK   <---- irrelevant for debug 

15:18:14.934 -> first: {"id":"Port","msg":"fff"}       <----[A] 

15:18:14.934 -> duplicate: {"id":"Port","msg":"fff"}   <----[B]

15:18:14.934 -> second: id                             <----[C]

15:18:14.934 -> third: id                              <----[D]

15:18:14.934 -> duplicate2: {"id":"Port","msg":"fff"}  <----[E]

15:18:14.934 -> Error. no such key. got reply: {"id":"Port","msg":"fff"}

Is there a reason for that ? is it a bug ?

user3430: When you pass a char* input to deserializeJson(), it alters the input to avoid making useless copies.
This is the "zero-copy" mode of ArduinoJson.
In this mode, the JSON parser modifies the input in-place. The following modifications are performed:

'\0' are inserted at the end of each string
Escaped special characters (like \n) are unescaped

Example:
char[] json = "{\"hello\":\"world\"}";
deserializeJson(doc, json);

After executing the line above, the input variable probably contains something like: "hello\0world\0".
You can find more details in the documentation

48730: <p>I'm using <code>RF24</code> library to send messages between 2 MCU's : 1) ESP8266 (no Wifi, same code can be compiled to any Arduino board) 2) pro-Micro.</p>
<p>Message is sent in JSON format, while using <code>ArduinoJSON</code> library to <code>serialize</code> and <code>deserialize</code> messages.</p>
<p>Altough entire code works as expected, I get an error in &quot;RFread&quot; function, which <code>_readmsg</code> array loses its content after using <code>deserializeJson</code>.</p>
<p>Attached below  relevant <strong>part</strong> of &quot;RFread&quot; function. Explanations in code below. Please notice &quot;Mark [X]&quot; in code and Serial output:</p>
<pre><code>char _readmsg[32];                                &lt;---- Storing input in this array
    char t2[32];                                  &lt;---- variable to clone value
    radio.read(&amp;_readmsg, sizeof(_readmsg));      &lt;---- getting RF input and store it in `_readmsg`
    strcpy(t2, _readmsg);                         &lt;---- cloning, part of error seeking

    Serial.print(&quot;first: &quot;);                      &lt;---- printing initial value stored. OK. marked [A] in Serial output
    Serial.println(_readmsg);
    Serial.print(&quot;duplicate: &quot;);                  &lt;---- printing clone. OK. marked [B] in Serial output
    Serial.println(t2);
    
    if (key != nullptr)                           &lt;--- check if &quot;msg&quot; key was sent in message
    {
      StaticJsonDocument&lt;80&gt; DOC;
      deserializeJson(DOC, _readmsg);             &lt;---- **error beyond this point**
      Serial.print(&quot;second: &quot;);
      Serial.println(_readmsg);                   &lt;---- printing wrong value. marked [C] in Serial output

      if (DOC.containsKey(key))
      {
        const char *outmsg = DOC[key];
        if (out != nullptr)
        {
          strcpy(out, outmsg);
          return true;
        }
      }
      else
      {
        Serial.print(&quot;third: &quot;);               
        Serial.println(_readmsg);              &lt;---- still error. marked [D] in Serial output
        Serial.print(&quot;duplicate2: &quot;);
        Serial.println(t2);                    &lt;---- clone variable is OK. marked [E] in Serial output
        strcpy(out, t2); // if key not present, return entire message
        return 0;
      }
</code></pre>
<p>and in Serial port:</p>
<pre><code>message sent OK   &lt;---- irrelevant for debug 

15:18:14.934 -&gt; first: {&quot;id&quot;:&quot;Port&quot;,&quot;msg&quot;:&quot;fff&quot;}       &lt;----[A] 

15:18:14.934 -&gt; duplicate: {&quot;id&quot;:&quot;Port&quot;,&quot;msg&quot;:&quot;fff&quot;}   &lt;----[B]

15:18:14.934 -&gt; second: id                             &lt;----[C]

15:18:14.934 -&gt; third: id                              &lt;----[D]

15:18:14.934 -&gt; duplicate2: {&quot;id&quot;:&quot;Port&quot;,&quot;msg&quot;:&quot;fff&quot;}  &lt;----[E]

15:18:14.934 -&gt; Error. no such key. got reply: {&quot;id&quot;:&quot;Port&quot;,&quot;msg&quot;:&quot;fff&quot;}
</code></pre>
<p>Is there a reason for that ? is it a bug ?</p>
 3430: <p>When you pass a <code>char*</code> input to <a href="https://arduinojson.org/v6/api/json/deserializejson/" rel="nofollow noreferrer">deserializeJson()</a>, it alters the input to avoid making useless copies.<br />
This is the &quot;zero-copy&quot; mode of ArduinoJson.</p>
<p>In this mode, the JSON parser modifies the input in-place. The following modifications are performed:</p>
<ol>
<li><code>'\0'</code> are inserted at the end of each string</li>
<li>Escaped special characters (like <code>\n</code>) are unescaped</li>
</ol>
<p>Example:</p>
<pre class="lang-cpp prettyprint-override"><code>char[] json = &quot;{\&quot;hello\&quot;:\&quot;world\&quot;}&quot;;
deserializeJson(doc, json);
</code></pre>
<p>After executing the line above, the input variable probably contains something like: <code>&quot;hello\0world\0&quot;</code>.</p>
<p>You can find more details <a href="https://arduinojson.org/v6/faq/why-is-the-input-modified/" rel="nofollow noreferrer">in the documentation</a></p>
