user72407: I am trying to retrieve JSON mqtt message I received in ESP32.
void mqttMsgCallback(char* topic, byte* payload, unsigned int length) {
    payload[length] = '\0';
    String _message = String((char*)payload);
    String _topic = String(topic);
    if (_topic.equals("Sys.GetInfo/"+getMacAddr()) == 1)
    {
      Serial.println("Message arrived for sys.GetInfo");
      StaticJsonDocument <256> msg1;
      Serial.println(_message);
      deserializeJson(msg1,_message);
      String callbackTopic = msg1["callbackTopic"];
      Serial.println(callbackTopic);
    }
}

The issue is when I publish mosquitto_pub -t "Sys.GetInfo/2462ABFC2CD0" -m "{"callbackTopic" : "1234"}" it works well like callbackTopic as 1234.
but when I publish mosquitto_pub -t "Sys.GetInfo/2462ABFC2CD0" -m "{"callbackTopic" : "xyz"}"  it prints callbackTopic value as null.
Please point me if I an missing something.
Arduino version 1.8.15
ArduinoJson : 6.18.2
Borad : ESP32
Thanks

user4143: Your shell is stripping the " from inside the string. If you run the command:
$ echo "{"callbackTopic" : "xyz"}"

you get:
{callbackTopic : xyz}

so you see all the quotes are stripped. xyz isn't something that ArduinoJSON can parse. But 1234 is, so with the quotes stripped it's still considered valid.
You need to ensure the quotes aren't removed. There's two ways of doing this: escaping them, or encapsulating the string in single quotes which gives a more "literal" interpretation of the contents than double quotes:
Escaping:
"{\"callbackTopic\" : \"xyz\"}"

Single quotes:
'{"callbackTopic" : "xyz"}'

Either of those when used as a parameter to a command work - like:
$ echo '{"callbackTopic" : "xyz"}'
{"callbackTopic" : "xyz"}


72407: <p>I am trying to retrieve JSON mqtt message I received in ESP32.</p>
<pre><code>void mqttMsgCallback(char* topic, byte* payload, unsigned int length) {
    payload[length] = '\0';
    String _message = String((char*)payload);
    String _topic = String(topic);
    if (_topic.equals(&quot;Sys.GetInfo/&quot;+getMacAddr()) == 1)
    {
      Serial.println(&quot;Message arrived for sys.GetInfo&quot;);
      StaticJsonDocument &lt;256&gt; msg1;
      Serial.println(_message);
      deserializeJson(msg1,_message);
      String callbackTopic = msg1[&quot;callbackTopic&quot;];
      Serial.println(callbackTopic);
    }
}
</code></pre>
<p>The issue is when I publish <code>mosquitto_pub -t &quot;Sys.GetInfo/2462ABFC2CD0&quot; -m &quot;{&quot;callbackTopic&quot; : &quot;1234&quot;}&quot;</code> it works well like callbackTopic as 1234.</p>
<p>but when I publish <code>mosquitto_pub -t &quot;Sys.GetInfo/2462ABFC2CD0&quot; -m &quot;{&quot;callbackTopic&quot; : &quot;xyz&quot;}&quot; </code> it prints callbackTopic value as null.
Please point me if I an missing something.</p>
<p>Arduino version 1.8.15
ArduinoJson : 6.18.2
Borad : ESP32</p>
<p>Thanks</p>
 4143: <p>Your shell is stripping the &quot; from inside the string. If you run the command:</p>
<pre><code>$ echo &quot;{&quot;callbackTopic&quot; : &quot;xyz&quot;}&quot;
</code></pre>
<p>you get:</p>
<pre><code>{callbackTopic : xyz}
</code></pre>
<p>so you see all the quotes are stripped. <code>xyz</code> isn't something that ArduinoJSON can parse. But <code>1234</code> is, so with the quotes stripped it's still considered valid.</p>
<p>You need to ensure the quotes aren't removed. There's two ways of doing this: escaping them, or encapsulating the string in single quotes which gives a more &quot;literal&quot; interpretation of the contents than double quotes:</p>
<p>Escaping:</p>
<pre><code>&quot;{\&quot;callbackTopic\&quot; : \&quot;xyz\&quot;}&quot;
</code></pre>
<p>Single quotes:</p>
<pre><code>'{&quot;callbackTopic&quot; : &quot;xyz&quot;}'
</code></pre>
<p>Either of those when used as a parameter to a command work - like:</p>
<pre><code>$ echo '{&quot;callbackTopic&quot; : &quot;xyz&quot;}'
{&quot;callbackTopic&quot; : &quot;xyz&quot;}
</code></pre>
