How to embed a JSON as the other's value in the ArduinoJSON?

Describe the issue
As the title, Here is my JSON

{
  "sensor": {
    "CH1": {
      "status": "sucess",
      "waterLevel": "0.37m"
    },
    "CH2": {
      "status": "sucess",
      "waterLevel": "0.57m"
    }
  }
}

And here is my code

StaticJsonDocument<192> doc;

JsonObject sensor = doc.createNestedObject("sensor");

JsonObject sensor_CH1 = sensor.createNestedObject("CH1");
sensor_CH1["status"] = "sucess";
sensor_CH1["waterLevel"] = "0.37m";

JsonObject sensor_CH2 = sensor.createNestedObject("CH2");
sensor_CH2["status"] = "sucess";
sensor_CH2["waterLevel"] = "0.57m";

serializeJson(doc, output);

But want to define a char array like
const char *arrary = "{\"status\":\"success\", \"waterLevel\":\"0.37m\"}"

and

sensor[CH1] = array;

but there always has " " and " , how can I do?

the picture’s two way are failed.

Can you parse the char* in a JSON document first and set that as a attribute?

DynamicJsonDocument doc2(1024);
deserializeJson(doc2, aa);
doc["test"] = doc2;
1 Like

you are so brilliant,it can slove the problem, but I wonder there is the other good way,
I use your suggestion, thank you!!!