user55520: I want to communicate two (2) ESP32's via Json commands using ESPAsyncWeb.h. The master should have specific operations to execute and respond to the client, and the client should be able to send specific Json commands to ask questions and receive responses. I have tried the method below but is throwing me weird errors such as

cannot bind non-const lvalue reference of type 'ArduinoJson::JsonObject&' {aka 'ArduinoJson6185_91::OBjectRef&'} to an rvalue of type 'ArduinoJson6185_91::enable_if<true, ArduinJson6185_91::ObjectRef>::type' {aka 'ArduinoJson6185_91::ObjectRef'}

I am not sure how to implement the operations for sending Json and receiving response from the Server using ArduinoJson 6. If anyone could enligthen me on how to conduct such transactions I'd appreciate it.
 void setup(){

//start serial comm
//Broadcast as WiFi SoftAP

 server.on("/command", HTTP_POST, [](AsyncWebServerRequest *request, JsonVariant &json) 
          {JsonObject& jsonObj = json.as<JsonObject>();
           uint8_t command = jsonObj["C"];
           String response;
           switch(command){
                           case 0: response = "{\"SCAN\":\"received_scan\"}";
                           request -> send(200, "application/json", response);
                           return;
                           case 1: /*...similar stuff */

                           case 2: /*...*/
}});
server.begin();
}



user3430: 
cannot bind non-const lvalue reference of type 'ArduinoJson::JsonObject&' {aka 'ArduinoJson6185_91::ObjectRef&'} to an rvalue of type 'ArduinoJson6185_91::enable_if<true, ArduinJson6185_91::ObjectRef>::type' {aka 'ArduinoJson6185_91::ObjectRef'}

In other words, "cannot assign JsonObject to JsonObject&".
The compiler refuses to save a reference to a temporary variable because the reference would inevitably dangle.
To fix this issue, you must remove the ampersand (&) after JsonObject, like so:
JsonObject jsonObj = json.as<JsonObject>();

And it would be best if you also did the same for JsonVariant.
BTW, the cast from JsonVariant to JsonObject isn't necessary in your case, so you could simplify your program to:
server.on("/command", HTTP_POST,
          [](AsyncWebServerRequest* request, JsonVariant json) {
            switch (json["C"].as<uint8_t>()) {
              case 0:
                request->send(200, "application/json",
                              "{\"SCAN\":\"received_scan\"}");
                return;
                
              case 1: /*...similar stuff */

              case 2: /*...*/
            }
          });

I recommend that you have a look at ArduinoJson's documentation; I heard it's pretty good ;-)

55520: <p>I want to communicate two (2) ESP32's via Json commands using ESPAsyncWeb.h. The master should have specific operations to execute and respond to the client, and the client should be able to send specific Json commands to ask questions and receive responses. I have tried the method below but is throwing me weird errors such as</p>
<blockquote>
<p>cannot bind non-const lvalue reference of type 'ArduinoJson::JsonObject&amp;' {aka 'ArduinoJson6185_91::OBjectRef&amp;'} to an rvalue of type 'ArduinoJson6185_91::enable_if&lt;true, ArduinJson6185_91::ObjectRef&gt;::type' {aka 'ArduinoJson6185_91::ObjectRef'}</p>
</blockquote>
<p>I am not sure how to implement the operations for sending Json and receiving response from the Server using ArduinoJson 6. If anyone could enligthen me on how to conduct such transactions I'd appreciate it.</p>
<pre><code> void setup(){

//start serial comm
//Broadcast as WiFi SoftAP

 server.on(&quot;/command&quot;, HTTP_POST, [](AsyncWebServerRequest *request, JsonVariant &amp;json) 
          {JsonObject&amp; jsonObj = json.as&lt;JsonObject&gt;();
           uint8_t command = jsonObj[&quot;C&quot;];
           String response;
           switch(command){
                           case 0: response = &quot;{\&quot;SCAN\&quot;:\&quot;received_scan\&quot;}&quot;;
                           request -&gt; send(200, &quot;application/json&quot;, response);
                           return;
                           case 1: /*...similar stuff */

                           case 2: /*...*/
}});
server.begin();
}

</code></pre>
 3430: <blockquote>
<p>cannot bind non-const lvalue reference of type 'ArduinoJson::JsonObject&amp;' {aka 'ArduinoJson6185_91::ObjectRef&amp;'} to an rvalue of type 'ArduinoJson6185_91::enable_if&lt;true, ArduinJson6185_91::ObjectRef&gt;::type' {aka 'ArduinoJson6185_91::ObjectRef'}</p>
</blockquote>
<p>In other words, &quot;cannot assign <code>JsonObject</code> to <code>JsonObject&amp;</code>&quot;.
The compiler refuses to save a reference to a temporary variable because the reference would inevitably dangle.</p>
<p>To fix this issue, you must remove the ampersand (<code>&amp;</code>) after <code>JsonObject</code>, like so:</p>
<pre class="lang-cpp prettyprint-override"><code>JsonObject jsonObj = json.as&lt;JsonObject&gt;();
</code></pre>
<p>And it would be best if you also did the same for <code>JsonVariant</code>.</p>
<p>BTW, the cast from <a href="https://arduinojson.org/v6/api/jsonvariant/" rel="nofollow noreferrer"><code>JsonVariant</code></a> to <a href="https://arduinojson.org/v6/api/jsonobject/" rel="nofollow noreferrer"><code>JsonObject</code></a> isn't necessary in your case, so you could simplify your program to:</p>
<pre class="lang-cpp prettyprint-override"><code>server.on(&quot;/command&quot;, HTTP_POST,
          [](AsyncWebServerRequest* request, JsonVariant json) {
            switch (json[&quot;C&quot;].as&lt;uint8_t&gt;()) {
              case 0:
                request-&gt;send(200, &quot;application/json&quot;,
                              &quot;{\&quot;SCAN\&quot;:\&quot;received_scan\&quot;}&quot;);
                return;
                
              case 1: /*...similar stuff */

              case 2: /*...*/
            }
          });
</code></pre>
<p>I recommend that you have a look at <a href="https://arduinojson.org/v6/doc/" rel="nofollow noreferrer">ArduinoJson's documentation</a>; I heard it's pretty good ;-)</p>
