Skip to content

Commit

Permalink
Added support for JsonObject and JsonArray in save and append
Browse files Browse the repository at this point in the history
  • Loading branch information
thebigpotatoe committed Mar 19, 2021
1 parent f38cff1 commit c611fc9
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 2 deletions.
22 changes: 22 additions & 0 deletions examples/Effortless_Spiffs_Basic/Effortless_Spiffs_Basic.ino
Original file line number Diff line number Diff line change
Expand Up @@ -173,6 +173,28 @@ void setup() {
Serial.print("JSON Document is: ");
serializeJson(jsonDocument, Serial);
Serial.println();

JsonObject jobject = jsonDocument.to<JsonObject>();
if (writeToFlash) {
jobject["Value"] = random(0, 100000);
fileSystem.saveToFile("/jsonObject.txt", jobject);
} else {
fileSystem.openFromFile("/jsonObject.txt", jsonDocument);
}
Serial.print("JSON Object is: ");
serializeJson(jobject, Serial);
Serial.println();

JsonArray jarray = jsonDocument.to<JsonArray>();
if (writeToFlash) {
jarray[0] = random(0, 100000);
fileSystem.saveToFile("/jsonArray.txt", jarray);
} else {
fileSystem.openFromFile("/jsonArray.txt", jsonDocument);
}
Serial.print("JSON Array is: ");
serializeJson(jarray, Serial);
Serial.println();
#endif

// Reboot to see what values are stored
Expand Down
10 changes: 8 additions & 2 deletions src/Effortless_SPIFFS.h
Original file line number Diff line number Diff line change
Expand Up @@ -417,7 +417,10 @@ class eSPIFFS {
}
#if defined ARDUINOJSON_VERSION_MAJOR && ARDUINOJSON_VERSION_MAJOR == 6
template <class T>
typename Effortless_SPIFFS_Internal::enable_if<Effortless_SPIFFS_Internal::is_same<T, DynamicJsonDocument>::value, bool>::type
typename Effortless_SPIFFS_Internal::enable_if<Effortless_SPIFFS_Internal::is_same<T, DynamicJsonDocument>::value ||
Effortless_SPIFFS_Internal::is_same<T, JsonObject>::value ||
Effortless_SPIFFS_Internal::is_same<T, JsonArray>::value,
bool>::type
saveToFile(const char* _filename, T& _input) {
File file = getFile(_filename, "w");
if (file) {
Expand Down Expand Up @@ -510,7 +513,10 @@ class eSPIFFS {
}
#if defined ARDUINOJSON_VERSION_MAJOR && ARDUINOJSON_VERSION_MAJOR == 6
template <class T>
typename Effortless_SPIFFS_Internal::enable_if<Effortless_SPIFFS_Internal::is_same<T, DynamicJsonDocument>::value, bool>::type
typename Effortless_SPIFFS_Internal::enable_if<Effortless_SPIFFS_Internal::is_same<T, DynamicJsonDocument>::value ||
Effortless_SPIFFS_Internal::is_same<T, JsonObject>::value ||
Effortless_SPIFFS_Internal::is_same<T, JsonArray>::value,
bool>::type
appendToFile(const char* _filename, T& _input) {
File file = getFile(_filename, "a");
if (file) {
Expand Down

0 comments on commit c611fc9

Please sign in to comment.