Getting InvalidInput on deserializeJson()

Hi,

I'm using an Arduino Uno clone with ATmega 328P and ESP826 controllers onboard. Both controllers can communicate about serial. That works fine.

Now ESP connects to https server and gets a JSON response. Everything is stored in a DynamicJsonDocument. That works fine too.

My JSON response has some levels. Here is an example:

{
	"data":
		{
			"box_name":"BOX-25",
			"has_order":true,
			"order":
				{
					"order_nr":4733,
					"technician":"Otto de Flotto",
					"is_active":false,
				}
		},
	"version":1
}

After deserialisation of JSON server response everything is accessable in DynamicJsonDocument. Now I create a second Document a fill it with data from the original one. Thats works fine for level "data" but when I create a nested object "order" and fill a field (like "technician") it comes to InvalidInput by calling deserialalizeJson(). Why?

Here is my code ...

      const size_t capacity = JSON_OBJECT_SIZE(2) + 2*JSON_OBJECT_SIZE(3) + JSON_OBJECT_SIZE(12) + 690;
      DynamicJsonDocument doc(capacity);
      DynamicJsonDocument doc2(capacity);

      
      if (WiFi.status() == WL_CONNECTED) 
      { 
        
        WiFiClientSecure client;
        client.setInsecure();   

       
        if (!client.connect(host, httpsPort))
        {
          doc2["version"] = "FAIL";
          return doc2;
        }//if
        else   
        {
         client.print("GET " + url + " HTTP/1.0\r\n" +
                       "Host: " + host + "\r\n" +
                       "User-Agent: BuildFailureDetectorESP8266\r\n" +
                       "Connection: close\r\n\r\n");
         
          
          char status[32] = {0};
          client.readBytesUntil('\r', status, sizeof(status));
          if (strcmp(status, "HTTP/1.1 200 OK") != 0) 
          {
            doc2["version"] = "Unexpected response: " + String(status);
            return doc2;  
          }//if
          else
          {
            char endOfHeaders[] = "\r\n\r\n";
            if (!client.find(endOfHeaders)) 
            {
              doc2["version"] = "Invalid response";
              return doc2;
            }//if
            else
            {
              Serial.setTimeout(10000);

              DeserializationError error = deserializeJson(doc, client);  
              client.flush();

              if (error)
	      {
                doc2["version"] = "ESP: " + String(error.c_str());
                return doc2;
              }  
              else    
              {
                
		doc2["data"]["box_name"] 	= doc["data"]["box_name"]; 
                doc2["data"]["has_order"] 	= doc["data"]["has_order"]; 
                bool has_order 				= doc["data"]["has_order"]; 
				
        	if(has_order)  
        	{
        					
                  JsonObject order  = doc2.createNestedObject("order");
                  order["technician"] = doc["data"]["order"]["technician"];
                  
           	}
                else
                  doc2["data"]["box_name"] = "has_order = false";
                
                
                return doc2;  //Here it will be returned and sendet by serializeJson(...)
                
                
              }//else  
				  
            }//else 
				
          }//else   
          
        }//else  

      }//if

After that it will be sendet to ATMega by Serial ...

    //Auftragsstatus abfragen
    DynamicJsonDocument jdoc = getOrderStatus();  

    //JSON Document über Serielle Schnittstelle senden
    serializeJson(jdoc, Serial);