Serializing ArduinoJson V6 problem

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.

Any advice gratefully received.

Do you need to use ArduinoJSON? Which MCU are you using?

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.

  const size_t CAPACITY = JSON_ARRAY_SIZE(1);
  StaticJsonDocument<CAPACITY> docH;
  JsonArray arrayH =<JsonArray>();

  DynamicJsonDocument root(1024);
  root["name"] = "ESP32 Humidity";
  root["stat_t"] = "tele/ESP32/SENSOR";
  root["pl_avail"] = "online";
  root["pl_not_avail"] = "offline";
  root["uniq_id"] = "000001_ESP32_Humidity";
  JsonObject dev = root.createNestedObject("dev");
  dev["ids"] = arrayH;
  root["unit_of_meas"] = "%";
  root["dev_cla"] = "humidity";
  root["frc_upd"] = true; // Don't know what this does! just copied from Tasmota messaage.
  root["val_tpl"] = "{{value_json['ESP32']['Humidity']}}";
  char message[1024];
  serializeJson(root, message);
  client.publish("homeassistant/sensor/000001_ESP32_Humidity/config", message, true);

Which when printed prettily comes like:

"name": "ESP32 Humidity",
"stat_t": "tele/ESP32/SENSOR",
"pl_avail": "online",
"pl_not_avail": "offline",
"uniq_id": "000001_ESP32_Humidity",
"dev": {
"ids": [
"unit_of_meas": "%",
"dev_cla": "humidity",
"frc_upd": true,
"val_tpl": "{{value_json['ESP32']['Humidity']}}"

just as I wanted.

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.