muwerk Scheduler Library
A low-resource cooperative scheduler with MQTT-like queues for Arduinos, ATtiny up to ESP32
Loading...
Searching...
No Matches
jsonfile.h
1// jsonfile.h - the muwerk json file class
2
3#pragma once
4
5#include "ustd_platform.h"
6#include "ustd_array.h"
7#include "ustd_map.h"
8#include "muwerk.h"
9#include "filesystem.h"
10
11#include <Arduino_JSON.h> // Platformio lib no. 6249
12
13#ifndef MAX_FRICKEL_DEPTH
14#define MAX_FRICKEL_DEPTH 9
15#endif
16
17namespace ustd {
18
67class jsonfile {
68 private:
69 bool loaded = false;
70 bool forcenew = false;
71 bool autocommit = true;
72 String path = "/";
73 String filename = "";
74 JSONVar obj;
75
76 public:
77 jsonfile(bool auto_commit = true, bool force_new = false, String path = "/")
78 : forcenew(force_new), autocommit(auto_commit), path(path) {
87 obj = JSON.parse("{}");
88 }
89
90 void clear(bool auto_commit = true, bool force_new = false) {
97 filename = "";
98 obj = JSON.parse("{}");
99 autocommit = auto_commit;
100 forcenew = force_new;
101 loaded = false;
102 }
103
104 bool init(String basename, JSONVar &value, bool auto_commit = true) {
113 filename = basename;
114 obj = value;
115 autocommit = auto_commit;
116 forcenew = true;
117 loaded = false;
118 return autocommit ? commit() : true;
119 }
120
121 bool init(String basename, String value, bool auto_commit = true) {
129 JSONVar jv = JSON.parse(value);
130 return init(basename, jv, auto_commit);
131 }
132
133 bool initFromFile(String basename, String fn, bool auto_commit = true) {
141 bool result = loadFile(basename, fn);
142 if (result) {
143 autocommit = auto_commit;
144 forcenew = true;
145 return autocommit ? commit() : true;
146 }
147 return false;
148 }
149
150 String toString() const {
154 return JSON.stringify(obj);
155 }
156
157 bool commit() {
163 if (filename == "") {
164 DBG("Cannot commit uninitialized object");
165 return false;
166 }
167 String jsonString = JSON.stringify(obj);
168
169 DBG2("Writing file: " + path + filename + ".json, content: " + jsonString);
170
171 fs::File f = fsOpen(path + filename + ".json", "w");
172 if (!f) {
173 DBG("File " + path + filename + ".json can't be opened for write, failure.");
174 return false;
175 } else {
176 f.print(jsonString.c_str());
177 f.close();
178 forcenew = false;
179 return true;
180 }
181 }
182
183 bool exists(String key) {
188 ustd::array<String> keyparts;
189 JSONVar subobj;
190 if (prepareRead(key, keyparts, subobj)) {
191 DBG2("From " + key + ", element found.");
192 return true;
193 };
194 return false;
195 }
196
197 static bool atomicExists(String key) {
202 jsonfile jf;
203 return jf.exists(key);
204 }
205
206 bool remove(String key) {
211 JSONVar target;
212 if (!prepareWrite(key, target)) {
213 return false;
214 }
215 target = undefined;
216 return autocommit ? commit() : true;
217 }
218
219 static bool atomicRemove(String key) {
224 jsonfile jf;
225 return jf.remove(key);
226 }
227
228 bool readJsonVar(String key, JSONVar &value) {
236 ustd::array<String> keyparts;
237 if (!prepareRead(key, keyparts, value)) {
238 return false;
239 }
240 return true;
241 }
242
243 static bool atomicReadJsonVar(String key, JSONVar &value) {
251 jsonfile jf;
252 return jf.readJsonVar(key, value);
253 }
254
255 bool readJsonVarArray(String key, ustd::array<JSONVar> &values) {
263 ustd::array<String> keyparts;
264 JSONVar subobj;
265 if (!prepareRead(key, keyparts, subobj)) {
266 return false;
267 }
268 if (JSON.typeof(subobj) != "array") {
269 DBG("From " + key + ", element has wrong type '" + JSON.typeof(subobj) +
270 "' - expected 'array'");
271 return false;
272 }
273 values.resize(subobj.length());
274 for (int i = 0; i < subobj.length(); i++) {
275 JSONVar element(subobj[i]);
276 values[i] = element;
277 }
278 return true;
279 }
280
281 static bool atomicReadJsonVarArray(String key, ustd::array<JSONVar> &values) {
289 jsonfile jf;
290 return jf.readJsonVarArray(key, values);
291 }
292
293 bool readStringArray(String key, ustd::array<String> &values, bool strict = false) {
303 ustd::array<String> keyparts;
304 JSONVar subobj;
305 if (!prepareRead(key, keyparts, subobj)) {
306 return false;
307 }
308 if (JSON.typeof(subobj) != "array") {
309 DBG("From " + key + ", element has wrong type '" + JSON.typeof(subobj) +
310 "' - expected 'array'");
311 return false;
312 }
313 if (strict) {
314 // check that all elements are strings
315 for (int i = 0; i < subobj.length(); i++) {
316 if (JSON.typeof(subobj[i]) != "string") {
317 DBG("From " + key + ", array element " + String(i) + " has wrong type '" +
318 JSON.typeof(subobj[i]) + "' - expected 'string'");
319 return false;
320 }
321 }
322 }
323 values.resize(subobj.length());
324 for (int i = 0; i < subobj.length(); i++) {
325 values[i] = String((const char *)subobj[i]);
326 }
327 return true;
328 }
329
330 static bool atomicReadStringArray(String key, ustd::array<String> &values,
331 bool strict = false) {
341 jsonfile jf;
342 return jf.readStringArray(key, values, strict);
343 }
344
345 bool readBoolArray(String key, ustd::array<bool> &values, bool strict = false) {
355 ustd::array<String> keyparts;
356 JSONVar subobj;
357 if (!prepareRead(key, keyparts, subobj)) {
358 return false;
359 }
360 if (JSON.typeof(subobj) != "array") {
361 DBG("From " + key + ", element has wrong type '" + JSON.typeof(subobj) +
362 "' - expected 'array'");
363 return false;
364 }
365 if (strict) {
366 // check that all elements are bools
367 for (int i = 0; i < subobj.length(); i++) {
368 if (JSON.typeof(subobj[i]) != "boolean") {
369 DBG("From " + key + ", array element " + String(i) + " has wrong type '" +
370 JSON.typeof(subobj[i]) + "' - expected 'boolean'");
371 return false;
372 }
373 }
374 }
375 values.resize(subobj.length());
376 for (int i = 0; i < subobj.length(); i++) {
377 values[i] = (bool)subobj[i];
378 }
379 return true;
380 }
381
382 static bool atomicReadBoolArray(String key, ustd::array<bool> &values, bool strict = false) {
392 jsonfile jf;
393 return jf.readBoolArray(key, values, strict);
394 }
395
396 bool readDoubleArray(String key, ustd::array<double> &values, bool strict = false) {
406 ustd::array<String> keyparts;
407 JSONVar subobj;
408 if (!prepareRead(key, keyparts, subobj)) {
409 return false;
410 }
411 if (JSON.typeof(subobj) != "array") {
412 DBG("From " + key + ", element has wrong type '" + JSON.typeof(subobj) +
413 "' - expected 'array'");
414 return false;
415 }
416 if (strict) {
417 // check that all elements are bools
418 for (int i = 0; i < subobj.length(); i++) {
419 if (JSON.typeof(subobj[i]) != "number") {
420 DBG("From " + key + ", array element " + String(i) + " has wrong type '" +
421 JSON.typeof(subobj[i]) + "' - expected 'number'");
422 return false;
423 }
424 }
425 }
426 values.resize(subobj.length());
427 for (int i = 0; i < subobj.length(); i++) {
428 values[i] = (double)subobj[i];
429 }
430 return true;
431 }
432
433 static bool atomicReadDoubleArray(String key, ustd::array<double> &values,
434 bool strict = false) {
444 jsonfile jf;
445 return jf.readDoubleArray(key, values, strict);
446 }
447
448 bool readLongArray(String key, ustd::array<long> &values, bool strict = false) {
458 ustd::array<String> keyparts;
459 JSONVar subobj;
460 if (!prepareRead(key, keyparts, subobj)) {
461 return false;
462 }
463 if (JSON.typeof(subobj) != "array") {
464 DBG("From " + key + ", element has wrong type '" + JSON.typeof(subobj) +
465 "' - expected 'array'");
466 return false;
467 }
468 if (strict) {
469 // check that all elements are bools
470 for (int i = 0; i < subobj.length(); i++) {
471 if (JSON.typeof(subobj[i]) != "number") {
472 DBG("From " + key + ", array element " + String(i) + " has wrong type '" +
473 JSON.typeof(subobj[i]) + "' - expected 'number'");
474 return false;
475 }
476 }
477 }
478 values.resize(subobj.length());
479 for (int i = 0; i < subobj.length(); i++) {
480 values[i] = (long)subobj[i];
481 }
482 return true;
483 }
484
485 static bool atomicReadLongArray(String key, ustd::array<long> &values, bool strict = false) {
495 jsonfile jf;
496 return jf.readLongArray(key, values, strict);
497 }
498
499 bool readBool(String key, bool defaultVal) {
505 ustd::array<String> keyparts;
506 JSONVar subobj;
507 if (!prepareRead(key, keyparts, subobj)) {
508 return defaultVal;
509 }
510 if (JSON.typeof(subobj) != "boolean") {
511 DBG("From " + key + ", element has wrong type '" + JSON.typeof(subobj) +
512 "' - expected 'boolean'");
513 return defaultVal;
514 }
515 bool result = (bool)subobj;
516 DBG2("From " + key + ", value: " + (result ? "true" : "false"));
517 return result;
518 }
519
520 static bool atomicReadBool(String key, bool defaultVal) {
526 jsonfile jf;
527 return jf.readBool(key, defaultVal);
528 }
529
530 String readString(String key, String defaultVal = "") {
536 ustd::array<String> keyparts;
537 JSONVar subobj;
538 if (!prepareRead(key, keyparts, subobj)) {
539 return defaultVal;
540 }
541 if (JSON.typeof(subobj) != "string") {
542 DBG("From " + key + ", element has wrong type '" + JSON.typeof(subobj) +
543 "' - expected 'string'");
544 return defaultVal;
545 }
546 String result = (const char *)subobj;
547 DBG2("From " + key + ", value: " + result);
548 return result;
549 }
550
551 static String atomicReadString(String key, String defaultVal = "") {
557 jsonfile jf;
558 return jf.readString(key, defaultVal);
559 }
560
561 String readString(String key, unsigned int minLength, String defaultVal = "") {
568 String val = readString(key, defaultVal);
569 return val.length() < minLength ? defaultVal : val;
570 }
571
572 static String atomicReadString(String key, unsigned int minLength, String defaultVal = "") {
579 jsonfile jf;
580 return jf.readString(key, minLength, defaultVal);
581 }
582
583 double readDouble(String key, double defaultVal) {
589 ustd::array<String> keyparts;
590 JSONVar subobj;
591 if (!prepareRead(key, keyparts, subobj)) {
592 return defaultVal;
593 }
594 if (JSON.typeof(subobj) != "number") {
595 DBG("From " + key + ", element has wrong type '" + JSON.typeof(subobj) +
596 "' - expected 'number'");
597 return defaultVal;
598 }
599 double result = (double)subobj;
600 DBG2("From " + key + ", value: " + String(result));
601 return result;
602 }
603
604 static double atomicReadDouble(String key, double defaultVal) {
610 jsonfile jf;
611 return jf.readDouble(key, defaultVal);
612 }
613
614 double readDouble(String key, double minVal, double maxVal, double defaultVal) {
623 long val = readDouble(key, defaultVal);
624 return (val < minVal || val > maxVal) ? defaultVal : val;
625 }
626
627 static double atomicReadDouble(String key, double minVal, double maxVal, double defaultVal) {
636 jsonfile jf;
637 return jf.readDouble(key, minVal, maxVal, defaultVal);
638 }
639
640 long readLong(String key, long defaultVal) {
646 return (long)readDouble(key, (double)defaultVal);
647 }
648
649 static long atomicReadLong(String key, long defaultVal) {
655 jsonfile jf;
656 return jf.readLong(key, defaultVal);
657 }
658
659 long readLong(String key, long minVal, long maxVal, long defaultVal) {
668 long val = readLong(key, defaultVal);
669 return (val < minVal || val > maxVal) ? defaultVal : val;
670 }
671
672 static long atomicReadLong(String key, long minVal, long maxVal, long defaultVal) {
681 jsonfile jf;
682 return jf.readLong(key, minVal, maxVal, defaultVal);
683 }
684
685 bool writeJsonVar(String key, JSONVar &value) {
691 JSONVar target;
692 if (!prepareWrite(key, target)) {
693 return false;
694 }
695 target = value;
696 return autocommit ? commit() : true;
697 }
698
699 static bool atomicWriteJsonVar(String key, JSONVar &value) {
705 jsonfile jf;
706 return jf.writeJsonVar(key, value);
707 }
708
709 bool writeJsonVar(String key, String value) {
715 JSONVar jv = JSON.parse(value);
716 if (JSON.typeof(jv) == "undefined") {
717 DBG("Invalid JSON-value " + value);
718 return false;
719 }
720
721 JSONVar target;
722 if (!prepareWrite(key, target)) {
723 return false;
724 }
725 target = jv;
726 return autocommit ? commit() : true;
727 }
728
729 static bool atomicWriteJsonVar(String key, String value) {
735 jsonfile jf;
736 return jf.writeJsonVar(key, value);
737 }
738
739 bool writeString(String key, String value) {
745 JSONVar target;
746 if (!prepareWrite(key, target)) {
747 return false;
748 }
749 target = (const char *)value.c_str();
750 return autocommit ? commit() : true;
751 }
752
753 static bool atomicWriteString(String key, String value) {
759 jsonfile jf;
760 return jf.writeString(key, value);
761 }
762
763 bool writeStringArray(String key, ustd::array<String> &values) {
769 JSONVar target;
770 if (!prepareWrite(key, target)) {
771 return false;
772 }
773 target = JSON.parse("[]");
774 for (unsigned int i; i < values.length(); i++) {
775 target[i] = (const char *)values[i].c_str();
776 }
777 return autocommit ? commit() : true;
778 }
779
780 static bool atomicWriteStringArray(String key, ustd::array<String> &values) {
786 jsonfile jf;
787 return jf.writeStringArray(key, values);
788 }
789
790 bool writeBool(String key, bool value) {
796 JSONVar target;
797 if (!prepareWrite(key, target)) {
798 return false;
799 }
800 target = value;
801 return autocommit ? commit() : true;
802 }
803
804 static bool atomicWriteBool(String key, bool value) {
810 jsonfile jf;
811 return jf.writeBool(key, value);
812 }
813
814 bool writeBoolArray(String key, ustd::array<bool> &values) {
820 JSONVar target;
821 if (!prepareWrite(key, target)) {
822 return false;
823 }
824 target = JSON.parse("[]");
825 for (unsigned int i; i < values.length(); i++) {
826 target[i] = values[i];
827 }
828 return autocommit ? commit() : true;
829 }
830
831 static bool atomicWriteBoolArray(String key, ustd::array<bool> &values) {
837 jsonfile jf;
838 return jf.writeBoolArray(key, values);
839 }
840
841 bool writeDouble(String key, double value) {
847 JSONVar target;
848 if (!prepareWrite(key, target)) {
849 return false;
850 }
851 target = value;
852 return autocommit ? commit() : true;
853 }
854
855 static bool atomicWriteDouble(String key, double value) {
861 jsonfile jf;
862 return jf.writeDouble(key, value);
863 }
864
865 bool writeDoubleArray(String key, ustd::array<double> &values) {
871 JSONVar target;
872 if (!prepareWrite(key, target)) {
873 return false;
874 }
875 target = JSON.parse("[]");
876 for (unsigned int i; i < values.length(); i++) {
877 target[i] = values[i];
878 }
879 return autocommit ? commit() : true;
880 }
881
882 static bool atomicWriteDoubleArray(String key, ustd::array<double> &values) {
888 jsonfile jf;
889 return jf.writeDoubleArray(key, values);
890 }
891
892 bool writeLong(String key, long value) {
898 JSONVar target;
899 if (!prepareWrite(key, target)) {
900 return false;
901 }
902 target = value;
903 return autocommit ? commit() : true;
904 }
905
906 static bool atomicWriteLong(String key, long value) {
912 jsonfile jf;
913 return jf.writeLong(key, value);
914 }
915
916 bool writeLongArray(String key, ustd::array<long> &values) {
922 JSONVar target;
923 if (!prepareWrite(key, target)) {
924 return false;
925 }
926 target = JSON.parse("[]");
927 for (unsigned int i; i < values.length(); i++) {
928 target[i] = values[i];
929 }
930 return autocommit ? commit() : true;
931 }
932
933 static bool atomicWriteLongArray(String key, ustd::array<long> &values) {
939 jsonfile jf;
940 return jf.writeLongArray(key, values);
941 }
942
943 private:
944 bool loadFile(String basename, String fn) {
945 filename = basename;
946 fs::File f = fsOpen(fn, "r");
947 if (!f) {
948 return false;
949 }
950 String jsonstr = "";
951 if (!f.available()) {
952 DBG2("Opened " + fn + ", but no data in file!");
953 return false;
954 }
955 while (f.available()) {
956 // Lets read line by line from the file
957 String line = f.readStringUntil('\n');
958 jsonstr += line;
959 }
960 f.close();
961 JSONVar content = JSON.parse(jsonstr);
962 if (JSON.typeof(content) == "undefined") {
963 DBG("Parsing input file " + fn + "failed, invalid JSON!");
964 DBG2("Content: " + jsonstr);
965 return false;
966 }
967 DBG2("Input file " + fn + " successfully parsed");
968 DBG3("Content: " + jsonstr);
969 obj = content;
970 loaded = true;
971 return true;
972 }
973
974 bool checkLoad(String basename) {
975 if (basename != filename) {
976 filename = basename;
977 loaded = false;
978 }
979 if (loaded || forcenew) {
980 return true;
981 }
982 return loadFile(basename, path + basename + ".json");
983 }
984
985 bool prepareRead(String key, ustd::array<String> &keyparts, JSONVar &subobj,
986 bool objmode = false) {
987 normalize(key);
988 ustd::split(key, '/', keyparts);
989 if (keyparts.length() < (objmode ? 1 : 2)) {
990 DBG("Key-path too short, minimum needed is filename/topic, got: " + key);
991 return false;
992 }
993 if (!checkLoad(keyparts[0])) {
994 return false;
995 }
996 JSONVar iterator(obj);
997 for (unsigned int i = 1; i < keyparts.length() - 1; i++) {
998 JSONVar tmpCopy(iterator[keyparts[i]]);
999 iterator = tmpCopy;
1000 if (JSON.typeof(iterator) == "undefined") {
1001 DBG2("From " + key + ", element " + keyparts[i] + " not found.");
1002 return false;
1003 }
1004 }
1005 String lastKey = keyparts[keyparts.length() - 1];
1006 if (!iterator.hasOwnProperty(lastKey)) {
1007 DBG2("From " + key + ", element " + lastKey + " not found.");
1008 return false;
1009 } else {
1010 JSONVar tmpCopy(iterator[lastKey]);
1011 subobj = tmpCopy;
1012 }
1013 return true;
1014 }
1015
1016 bool prepareWrite(String key, JSONVar &target, bool objmode = false) {
1017 ustd::array<String> keyparts;
1018
1019 normalize(key);
1020 ustd::split(key, '/', keyparts);
1021 if (keyparts.length() < (objmode ? 1 : 2)) {
1022 DBG("Key-path too short, minimum needed is filename/topic, got: " + key);
1023 return false;
1024 }
1025 if (keyparts.length() > MAX_FRICKEL_DEPTH) {
1026 DBG("Key-path too long, maxdepth is " + String(MAX_FRICKEL_DEPTH) + ", got: " + key);
1027 return false;
1028 }
1029 if (!checkLoad(keyparts[0]) && forcenew) {
1030 DBG("Creating new file /" + keyparts[0] + ".json");
1031 }
1032
1033 // frickel
1034 switch (keyparts.length()) {
1035 case 1:
1036 // possible only in object mode
1037 target = obj;
1038 return true;
1039 case 2:
1040 target = obj[keyparts[1]];
1041 return true;
1042 case 3:
1043 target = obj[keyparts[1]][keyparts[2]];
1044 return true;
1045 case 4:
1046 target = obj[keyparts[1]][keyparts[2]][keyparts[3]];
1047 return true;
1048 case 5:
1049 target = obj[keyparts[1]][keyparts[2]][keyparts[3]][keyparts[4]];
1050 return true;
1051 case 6:
1052 target = obj[keyparts[1]][keyparts[2]][keyparts[3]][keyparts[4]][keyparts[5]];
1053 return true;
1054 case 7:
1055 target =
1056 obj[keyparts[1]][keyparts[2]][keyparts[3]][keyparts[4]][keyparts[5]][keyparts[6]];
1057 return true;
1058 case 8:
1059 target = obj[keyparts[1]][keyparts[2]][keyparts[3]][keyparts[4]][keyparts[5]]
1060 [keyparts[6]][keyparts[7]];
1061 return true;
1062 case 9:
1063 target = obj[keyparts[1]][keyparts[2]][keyparts[3]][keyparts[4]][keyparts[5]]
1064 [keyparts[6]][keyparts[7]][keyparts[8]];
1065 return true;
1066 default:
1067 DBG("SERIOUS PROGRAMMING ERROR - MAX_FRICKEL_DEV higher than implemented support "
1068 "in " __FILE__ " line number " +
1069 String(__LINE__));
1070 return false;
1071 }
1072 }
1073
1074 static void normalize(String &src) {
1075 if (src.c_str()[0] == '/') {
1076 src = src.substring(1);
1077 }
1078 }
1079};
1080
1081} // namespace ustd
muwerk JSON File Class
Definition jsonfile.h:67
bool readDoubleArray(String key, ustd::array< double > &values, bool strict=false)
Definition jsonfile.h:396
bool writeDouble(String key, double value)
Definition jsonfile.h:841
static double atomicReadDouble(String key, double minVal, double maxVal, double defaultVal)
Definition jsonfile.h:627
static bool atomicReadDoubleArray(String key, ustd::array< double > &values, bool strict=false)
Definition jsonfile.h:433
static bool atomicWriteBool(String key, bool value)
Definition jsonfile.h:804
String readString(String key, unsigned int minLength, String defaultVal="")
Definition jsonfile.h:561
static bool atomicWriteBoolArray(String key, ustd::array< bool > &values)
Definition jsonfile.h:831
static bool atomicReadJsonVar(String key, JSONVar &value)
Definition jsonfile.h:243
bool remove(String key)
Definition jsonfile.h:206
static bool atomicWriteJsonVar(String key, String value)
Definition jsonfile.h:729
double readDouble(String key, double minVal, double maxVal, double defaultVal)
Definition jsonfile.h:614
long readLong(String key, long defaultVal)
Definition jsonfile.h:640
static bool atomicWriteStringArray(String key, ustd::array< String > &values)
Definition jsonfile.h:780
static long atomicReadLong(String key, long defaultVal)
Definition jsonfile.h:649
bool writeLongArray(String key, ustd::array< long > &values)
Definition jsonfile.h:916
static bool atomicReadJsonVarArray(String key, ustd::array< JSONVar > &values)
Definition jsonfile.h:281
bool init(String basename, JSONVar &value, bool auto_commit=true)
Definition jsonfile.h:104
bool readStringArray(String key, ustd::array< String > &values, bool strict=false)
Definition jsonfile.h:293
static bool atomicReadBool(String key, bool defaultVal)
Definition jsonfile.h:520
bool readBoolArray(String key, ustd::array< bool > &values, bool strict=false)
Definition jsonfile.h:345
bool writeJsonVar(String key, JSONVar &value)
Definition jsonfile.h:685
bool writeDoubleArray(String key, ustd::array< double > &values)
Definition jsonfile.h:865
bool writeString(String key, String value)
Definition jsonfile.h:739
static bool atomicExists(String key)
Definition jsonfile.h:197
bool writeBoolArray(String key, ustd::array< bool > &values)
Definition jsonfile.h:814
static bool atomicWriteLong(String key, long value)
Definition jsonfile.h:906
bool readJsonVarArray(String key, ustd::array< JSONVar > &values)
Definition jsonfile.h:255
bool exists(String key)
Definition jsonfile.h:183
bool writeLong(String key, long value)
Definition jsonfile.h:892
bool readLongArray(String key, ustd::array< long > &values, bool strict=false)
Definition jsonfile.h:448
bool initFromFile(String basename, String fn, bool auto_commit=true)
Definition jsonfile.h:133
static long atomicReadLong(String key, long minVal, long maxVal, long defaultVal)
Definition jsonfile.h:672
jsonfile(bool auto_commit=true, bool force_new=false, String path="/")
Definition jsonfile.h:77
static bool atomicWriteString(String key, String value)
Definition jsonfile.h:753
bool commit()
Definition jsonfile.h:157
static String atomicReadString(String key, String defaultVal="")
Definition jsonfile.h:551
static bool atomicWriteDouble(String key, double value)
Definition jsonfile.h:855
bool init(String basename, String value, bool auto_commit=true)
Definition jsonfile.h:121
double readDouble(String key, double defaultVal)
Definition jsonfile.h:583
static bool atomicWriteLongArray(String key, ustd::array< long > &values)
Definition jsonfile.h:933
void clear(bool auto_commit=true, bool force_new=false)
Definition jsonfile.h:90
long readLong(String key, long minVal, long maxVal, long defaultVal)
Definition jsonfile.h:659
static bool atomicRemove(String key)
Definition jsonfile.h:219
bool readJsonVar(String key, JSONVar &value)
Definition jsonfile.h:228
static double atomicReadDouble(String key, double defaultVal)
Definition jsonfile.h:604
String readString(String key, String defaultVal="")
Definition jsonfile.h:530
static bool atomicWriteJsonVar(String key, JSONVar &value)
Definition jsonfile.h:699
static String atomicReadString(String key, unsigned int minLength, String defaultVal="")
Definition jsonfile.h:572
static bool atomicReadStringArray(String key, ustd::array< String > &values, bool strict=false)
Definition jsonfile.h:330
bool readBool(String key, bool defaultVal)
Definition jsonfile.h:499
static bool atomicReadLongArray(String key, ustd::array< long > &values, bool strict=false)
Definition jsonfile.h:485
static bool atomicReadBoolArray(String key, ustd::array< bool > &values, bool strict=false)
Definition jsonfile.h:382
bool writeStringArray(String key, ustd::array< String > &values)
Definition jsonfile.h:763
String toString() const
Definition jsonfile.h:150
bool writeJsonVar(String key, String value)
Definition jsonfile.h:709
bool writeBool(String key, bool value)
Definition jsonfile.h:790
static bool atomicWriteDoubleArray(String key, ustd::array< double > &values)
Definition jsonfile.h:882
The muwerk namespace.
Definition console.h:15
fs::File fsOpen(String filename, String mode)
Definition filesystem.h:113
void split(String &src, char delimiter, array< String > &result)
Definition muwerk.h:62