0

I have a JSON file stored in ESP8266, which I read need to add a value and save it back to file on ESP8266.

I have an array at when saved at the first time as:

JsonArray data = doc.createNestedArray("data");
        data.add(48.756080);
        data.add(2.302038);

BUT after retrieving it from ESP8266:

File readFile = SPIFFS.open(filename, "r");
        DeserializationError error = deserializeJson(_doc, readFile);
        if (error) {
                Serial.println(F("Failed to read file"));
        }
        serializeJson(doc, readFile);

        JsonArray data = doc.createNestedArray("data");
        data.add(12345678); // <--- new value to add

all the data in data is replaced with new value only.

My workaround was to save store data from data everytime I want to add new value as follows and store array as new one back again:

long lista[10];
for (int u=0; u<2; u++){
          doc["data"][u]=lista[u];
        }

is there a better way ?

Guy

  • 2
    I would try doc["data"].add(12345678); – Juraj Apr 25 at 7:14
  • thank you- it works – Guy . D Apr 25 at 8:48

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.