I'm trying to copy the formatting of Tasmota MQTT messages formatted in Json but there's one bit that's got me stumped. I'm no expert but can usually understand example code and work with it.
I want to get {...,"dev":{"ids":["000001"]},...} but the nearest I can get is {...,"dev":{"ids":"000001"},...}. It looks like an array with just one element.
My code for what I've achieved is...
DynamicJsonDocument root(512);
root["stuff"] = "stuff"; // Several lines of this sort
JsonObject dev = root.createNestedObject("dev");
dev["ids"] = "000001";
root["more stuff" = "more stuff"; // More lines of this sort
I've tried with the createNestedArray but just end up with loads of errors.
I'm sure it's pretty simple but I just have seen no examples. I did think to look in the Tasmota code itself but just don't know where to start. I even think I should not bother with Json and just type the whole string out in the code but that's a bit defeatist.
I don't know. I've only just discovered Json since getting into Tasmota, Home Assistant and MQTT in the last couple of weeks. Actually, I think it would be easier and more efficient, to just type a long string as it's static. Maybe just use arduinoJson for the reporting of eg temperatures.
I'm running this code on an ESP32 but could well be doing the same on a 8266.
I've managed to solve the problem myself anyway now by creating the array separately and then inserting it at the appropriate point.
Having done all that, I think I'll just print it as a string into the Serial monitor and then copy it back into the code as a string for publishing, deleting the constructing Json code.