Well, its seems that the current example is indeed wrong (at least with the current ArduinoJson library)!
Here is the corrections that must be made to be able to use JSON MQTT messages:
// The original code:
//void on_json_message(JsonObject &root)
// must be changed to this:
void on_json_message(JsonObject root)
{
if (!root.containsKey("key"))
return;
int value = root["key"];
// do something with Json Object
// publish JSON using lambda syntax
// The original code:
// publish_json("the/other/json/topic", [=](JsonObject &root2)
// must be changed to this:
publish_json("the/other/json/topic", [=](JsonObject root2)
{ root2["key"] = "Hello World"; });
}
That is, in both cases the & must be removed!
As I suspected this is something related with the migration of ArduinoJson from v5 to v6!