Unexplained behavior of char array after using `deserializeJson` 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 &quot;RFread&quot; function, which _readmsg array loses its content after using deserializeJson.
Attached below  relevant part of &quot;RFread&quot; function. Explanations in code below. Please notice &quot;Mark [X]&quot; in code and Serial output:
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;
      }

and in Serial port:
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;}

Is there a reason for that ? is it a bug ?
When you pass a char* input to deserializeJson(), it alters the input to avoid making useless copies.
This is the &quot;zero-copy&quot; 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 = &quot;{\&quot;hello\&quot;:\&quot;world\&quot;}&quot;;
deserializeJson(doc, json);

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