Change a nested key inside a json by Arduinojson 5

Hi everybody,
I have a problem changing the value of a nested key inside a json. I couldn't change the mentioned value as below:

"Switches": [
"Name": "Room Ligth",
"state": true
"Sensors": [
"Name": "Home Temperature",
"value": 423 // << this value--------------

what Im looking for is something like this:


but when I write the above line my "Weoms mini D1" crashes and restarts.

huge thanks for any ideas

can you try this code:

#include <ArduinoJson.h>

char jsonTxt[] = "{\"Switches\": [{\"Name\": \"Room Ligth\",\"state\": true}],\"Sensors\": [{\"Name\": \"Home Temperature\",\"value\": 423}]}";

void setup() {
  DynamicJsonDocument doc(200);
  deserializeJson(doc, jsonTxt);
  long value = doc["Sensors"][0]["value"];
  Serial.print(F("Initial Value = ")); Serial.println(value);
  doc["Sensors"][0]["value"] = 42;
  value = doc["Sensors"][0]["value"];
  Serial.print(F("After modification, Value = ")); Serial.println(value);

void loop() {}

if all goes well, Serial Monitor (@ 115200 bauds) will show

Initial Value = 423
After modification, Value = 42

tnx alot J-M-L

This topic was automatically closed 120 days after the last reply. New replies are no longer allowed.