Need help with json object

im trying to make a json object format but im having trouble formatting the code. Can i use char to make the object or should i use String?

I need the format to obviously look like this,

{"tm1t1rt":[0],"tm1t2rt":[0]}

I can't even get the first key coded into the string.

this is what i have so far,

char JSON[] = "{\"tm1t1rt\":[" + tm1runTime+"]}";

But im getting error,

invalid operands of types 'const char*' and 'const char [3]' to binary 'operator+'

Ive got a more complete function that works but i dont know if this is a bad idea or not. Is using string like this okay? My json object will be about 6 times that size and currently i have to split it up into multi json objects for my web server because arduinojson size limit. I would like to just add them all to 1 big json object and only request from the esp web server 1 time so this is why i came up with this idea. is this function with String going to cause any big problems. is there a better way?

void handlegettmjson5() {
  char a[15];
  char b[15];
  char c[15];
  char d[15];
  char e[15];
  char f[15];
  char g[15];
  char h[15];
  char i[15];
  char j[15];
  char k[15];
  char l[15];
  char m[15];
  char n[15];
  char o[15];
  char p[15];
  char q[15];
  if (_EEPROM.enabled) {
    sprintf(c, "%s", "Enabled");
  } else {
    sprintf(c, "%s", "Disabled");
  }
  if (_EEPROM.timerEnabled[0]) {
    sprintf(d, "%s", "Enabled");
  } else {
    sprintf(d, "%s", "Disabled");
  }
  if (_EEPROM.timerEnabled[1]) {
    sprintf(e, "%s", "Enabled");
  } else {
    sprintf(e, "%s", "Disabled");
  }
  if (_EEPROM.timerEnabled[2]) {
    sprintf(f, "%s", "Enabled");
  } else {
    sprintf(f, "%s", "Disabled");
  }
  if (_EEPROM.timerEnabled[3]) {
    sprintf(g, "%s", "Enabled");
  } else {
    sprintf(g, "%s", "Disabled");
  }
  if (_EEPROM.timerEnabled[4]) {
    sprintf(h, "%s", "Enabled");
  } else {
    sprintf(h, "%s", "Disabled");
  }
  if (_EEPROM.cleanMode) {
    sprintf(i, "%s", "Enabled");
  } else {
    sprintf(i, "%s", "Disabled");
  }

  if (!_EEPROM.timerRunning[0]) {
    sprintf(j, "%s", "Running");
  } else {
    sprintf(j, "%s", "Not Running");
  }

  if (!_EEPROM.timerRunning[1]) {
    sprintf(k, "%s", "Running");
  } else {
    sprintf(k, "%s", "Not Running");
  }
  if (!_EEPROM.timerRunning[2]) {
    sprintf(l, "%s", "Running");
  } else {
    sprintf(l, "%s", "Not Running");
  }
  if (!_EEPROM.timerRunning[3]) {
    sprintf(m, "%s", "Running");
  } else {
    sprintf(m, "%s", "Not Running");
  }
  if (!_EEPROM.timerRunning[4]) {
    sprintf(n, "%s", "Running");
  } else {
    sprintf(n, "%s", "Not Running");
  }
  if (_EEPROM.cleanMode) {
    sprintf(o, "%s", "Enabled");
  } else {
    sprintf(o, "%s", "Disabled");
  }
  if (!_EEPROM.timerRunning[5]) {
    sprintf(p, "%s", "Running");
  } else {
    sprintf(p, "%s", "Not Running");
  }
  server.send(200, "text/plane",                            "{\"tm1t1rt\":[" +
              String(_EEPROM.timerRuntimes[0]) + "]" + "," + "\"tm1t2rt\":[" +
              String(_EEPROM.timerRuntimes[1]) + "]" + "," + "\"tm1t3rt\":[" +
              String(_EEPROM.timerRuntimes[2]) + "]" + "," + "\"tm1t4rt\":[" +
              String(_EEPROM.timerRuntimes[3]) + "]" + "," + "\"tm1t5rt\":[" +
              String(_EEPROM.timerRuntimes[4]) + "]" + "," + "\"tm1cleanrt\":[" +
              String(_EEPROM.timerRuntimes[5]) + "]" + "," + "\"tm1status\":[\"" +
              String(c) + "\"]" + "," + "\"tm1t1s\":[\"" +
              String(d) + "\"]" + "," + "\"tm1t2s\":[\"" +
              String(e) + "\"]" + "," + "\"tm1t3s\":[\"" +
              String(f) + "\"]" + "," + "\"tm1t4s\":[\"" +
              String(g) + "\"]" + "," + "\"tm1t5s\":[\"" +
              String(h) + "\"]" + "," + "\"tm1cleans\":[\"" +
              String(i) + "\"]" + "," + "\"tm1t1status\":[\"" +
              String(j) + "\"]" + "," + "\"tm1t2status\":[\"" +
              String(k) + "\"]" + "," + "\"tm1t3status\":[\"" +
              String(l) + "\"]" + "," + "\"tm1t4status\":[\"" +
              String(m) + "\"]" + "," + "\"tm1t5status\":[\"" +
              String(n) + "\"]" + "," + "\"lightstatus\":[" +
              String(lightsOn) + "]" + "," + "\"tm1cleanss\":[\"" +
              String(o) + "\"]" + "," + "\"tm1cleanstatus\":[\"" +
              String(p) + "\"]"
              + "}" );


}

I have it working, it seems like it works okay. is there anything wrong with the way im using String here? is this doomed to crash my sketch.

void handlegettmjson5() {
  char a[15];
  char b[15];
  char c[15];
  char d[15];
  char e[15];
  char f[15];
  char g[15];
  char h[15];
  char i[15];
  char j[15];
  char k[15];
  char l[15];
  char m[15];
  char n[15];
  char o[15];
  char p[15];
  char q[15];
  if (_EEPROM.enabled) {
    sprintf(c, "%s", "Enabled");
  } else {
    sprintf(c, "%s", "Disabled");
  }
  if (_EEPROM.timerEnabled[0]) {
    sprintf(d, "%s", "Enabled");
  } else {
    sprintf(d, "%s", "Disabled");
  }
  if (_EEPROM.timerEnabled[1]) {
    sprintf(e, "%s", "Enabled");
  } else {
    sprintf(e, "%s", "Disabled");
  }
  if (_EEPROM.timerEnabled[2]) {
    sprintf(f, "%s", "Enabled");
  } else {
    sprintf(f, "%s", "Disabled");
  }
  if (_EEPROM.timerEnabled[3]) {
    sprintf(g, "%s", "Enabled");
  } else {
    sprintf(g, "%s", "Disabled");
  }
  if (_EEPROM.timerEnabled[4]) {
    sprintf(h, "%s", "Enabled");
  } else {
    sprintf(h, "%s", "Disabled");
  }
  if (_EEPROM.cleanMode) {
    sprintf(i, "%s", "Enabled");
  } else {
    sprintf(i, "%s", "Disabled");
  }

  if (!_EEPROM.timerRunning[0]) {
    sprintf(j, "%s", "Running");
  } else {
    sprintf(j, "%s", "Not Running");
  }

  if (!_EEPROM.timerRunning[1]) {
    sprintf(k, "%s", "Running");
  } else {
    sprintf(k, "%s", "Not Running");
  }
  if (!_EEPROM.timerRunning[2]) {
    sprintf(l, "%s", "Running");
  } else {
    sprintf(l, "%s", "Not Running");
  }
  if (!_EEPROM.timerRunning[3]) {
    sprintf(m, "%s", "Running");
  } else {
    sprintf(m, "%s", "Not Running");
  }
  if (!_EEPROM.timerRunning[4]) {
    sprintf(n, "%s", "Running");
  } else {
    sprintf(n, "%s", "Not Running");
  }
  if (_EEPROM.cleanMode) {
    sprintf(o, "%s", "Enabled");
  } else {
    sprintf(o, "%s", "Disabled");
  }
  if (!_EEPROM.timerRunning[5]) {
    sprintf(p, "%s", "Running");
  } else {
    sprintf(p, "%s", "Not Running");
  }
  server.send(200, "text/plane",                            "{\"tm1t1rt\":[" +
              String(_EEPROM.timerRuntimes[0]) + "]" + "," + "\"tm1t2rt\":[" +
              String(_EEPROM.timerRuntimes[1]) + "]" + "," + "\"tm1t3rt\":[" +
              String(_EEPROM.timerRuntimes[2]) + "]" + "," + "\"tm1t4rt\":[" +
              String(_EEPROM.timerRuntimes[3]) + "]" + "," + "\"tm1t5rt\":[" +
              String(_EEPROM.timerRuntimes[4]) + "]" + "," + "\"tm1cleanrt\":[" +
              String(_EEPROM.timerRuntimes[5]) + "]" + "," + "\"tm1status\":[\"" +
              String(c) + "\"]" + "," + "\"tm1t1s\":[\"" +
              String(d) + "\"]" + "," + "\"tm1t2s\":[\"" +
              String(e) + "\"]" + "," + "\"tm1t3s\":[\"" +
              String(f) + "\"]" + "," + "\"tm1t4s\":[\"" +
              String(g) + "\"]" + "," + "\"tm1t5s\":[\"" +
              String(h) + "\"]" + "," + "\"tm1cleans\":[\"" +
              String(i) + "\"]" + "," + "\"tm1t1status\":[\"" +
              String(j) + "\"]" + "," + "\"tm1t2status\":[\"" +
              String(k) + "\"]" + "," + "\"tm1t3status\":[\"" +
              String(l) + "\"]" + "," + "\"tm1t4status\":[\"" +
              String(m) + "\"]" + "," + "\"tm1t5status\":[\"" +
              String(n) + "\"]" + "," + "\"lightstatus\":[" +
              String(lightsOn) + "]" + "," + "\"tm1cleanss\":[\"" +
              String(o) + "\"]" + "," + "\"tm1cleanstatus\":[\"" +
              String(p) + "\"]" + "," + "\"labelt1\":[\"" +
              String(_EEPROM.label[0]) + "\"]" + "," + "\"labelt2\":[\"" +
              String(_EEPROM.label[1]) + "\"]" + "," + "\"labelt3\":[\"" +
              String(_EEPROM.label[2]) + "\"]" + "," + "\"labelt4\":[\"" +
              String(_EEPROM.label[3]) + "\"]" + "," + "\"labelt5\":[\"" +
              String(_EEPROM.label[4]) + "\"]" + "," + "\"labelt6\":[\"" +
              String(_EEPROM.label[5]) + "\"]" + "," + "\"t1otdv\":[" +
              String(_EEPROM.timerTimes[0][0]) + "]" + "," + "\"t1offtdv\":[" +
              String(_EEPROM.timerTimes[0][1]) + "]" + "," + "\"t1otnv\":[" +
              String(_EEPROM.timerTimes[0][2]) + "]" + "," + "\"t1offtnv\":[" +
              String(_EEPROM.timerTimes[0][3]) + "]" + "," + "\"t2otdv\":[" +
              String(_EEPROM.timerTimes[1][0]) + "]" + "," + "\"t2offtdv\":[" +
              String(_EEPROM.timerTimes[1][1]) + "]" + "," + "\"t2otnv\":[" +
              String(_EEPROM.timerTimes[1][2]) + "]" + "," + "\"t2offtnv\":[" +
              String(_EEPROM.timerTimes[1][3]) + "]" + "," + "\"t3otdv\":[" +
              String(_EEPROM.timerTimes[2][0]) + "]" + "," + "\"t3offtdv\":[" +
              String(_EEPROM.timerTimes[2][1]) + "]" + "," + "\"t3otnv\":[" +
              String(_EEPROM.timerTimes[2][2]) + "]" + "," + "\"t3offtnv\":[" +
              String(_EEPROM.timerTimes[2][3]) + "]" + "," + "\"t4otdv\":[" +
              String(_EEPROM.timerTimes[3][0]) + "]" + "," + "\"t4offtdv\":[" +
              String(_EEPROM.timerTimes[3][1]) + "]" + "," + "\"t4otnv\":[" +
              String(_EEPROM.timerTimes[3][2]) + "]" + "," + "\"t4offtnv\":[" +
              String(_EEPROM.timerTimes[3][3]) + "]" + "," + "\"t5otdv\":[" +
              String(_EEPROM.timerTimes[4][0]) + "]" + "," + "\"t5offtdv\":[" +
              String(_EEPROM.timerTimes[4][1]) + "]" + "," + "\"t5otnv\":[" +
              String(_EEPROM.timerTimes[4][2]) + "]" + "," + "\"t5offtnv\":[" +
              String(_EEPROM.timerTimes[4][3]) + "]" + "," + "\"cleanondurationv\":[" +
              String(_EEPROM.cleanOnTime) + "]"  + "," + "\"cleanoffdurationv\":[" +
              String(_EEPROM.cleanOffTime) + "]" + "," + "\"disinfectdurationv\":[" +
              String(_EEPROM.cleanDisinfectTime) + "]"  + "," + "\"datetime\":[\"" +
              String(str) + "\"]"

              + "}" );

here is the output of the json object,

{"tm1t1rt":[0],"tm1t2rt":[0],"tm1t3rt":[0],"tm1t4rt":[0],"tm1t5rt":[0],"tm1cleanrt":[1],"tm1status":["Disabled"],"tm1t1s":["Enabled"],"tm1t2s":["Enabled"],"tm1t3s":["Enabled"],"tm1t4s":["Enabled"],"tm1t5s":["Enabled"],"tm1cleans":["Enabled"],"tm1t1status":["Not Running"],"tm1t2status":["Not Running"],"tm1t3status":["Not Running"],"tm1t4status":["Not Running"],"tm1t5status":["Not Running"],"lightstatus":[0],"tm1cleanss":["Enabled"],"tm1cleanstatus":["Running"],"labelt1":["default"],"labelt2":["default"],"labelt3":["default"],"labelt4":["default"],"labelt5":["default"],"labelt6":["default"],"t1otdv":[2000],"t1offtdv":[120000],"t1otnv":[2000],"t1offtnv":[120000],"t2otdv":[2000],"t2offtdv":[120000],"t2otnv":[2000],"t2offtnv":[120000],"t3otdv":[2000],"t3offtdv":[120000],"t3otnv":[2000],"t3offtnv":[120000],"t4otdv":[2000],"t4offtdv":[120000],"t4otnv":[2000],"t4offtnv":[120000],"t5otdv":[2000],"t5offtdv":[120000],"t5otnv":[2000],"t5offtnv":[120000],"cleanondurationv":[8000],"cleanoffdurationv":[1000],"disinfectdurationv":[120000],"datetime":["2021/8/5 4:33:15"]}

here is what i originally had,

void handlegettmjson() {
  //yield();
  StaticJsonDocument<1000> doc;
  JsonArray tm1t1rt = doc.createNestedArray("tm1t1rt");
  JsonArray tm1t2rt = doc.createNestedArray("tm1t2rt");
  JsonArray tm1t3rt = doc.createNestedArray("tm1t3rt");
  JsonArray tm1t4rt = doc.createNestedArray("tm1t4rt");
  JsonArray tm1t5rt = doc.createNestedArray("tm1t5rt");

  JsonArray tm1cleanrt = doc.createNestedArray("tm1cleanrt");
  JsonArray tm1SS = doc.createNestedArray("tm1status");
  JsonArray tm1t1s = doc.createNestedArray("tm1t1s");
  JsonArray tm1t2s = doc.createNestedArray("tm1t2s");
  JsonArray tm1t3s = doc.createNestedArray("tm1t3s");
  JsonArray tm1t4s = doc.createNestedArray("tm1t4s");
  JsonArray tm1t5s = doc.createNestedArray("tm1t5s");
  JsonArray tm1cleans = doc.createNestedArray("tm1cleans");
  JsonArray tm1t1status = doc.createNestedArray("tm1t1status");
  JsonArray tm1t2status = doc.createNestedArray("tm1t2status");
  JsonArray tm1t3status = doc.createNestedArray("tm1t3status");
  JsonArray tm1t4status = doc.createNestedArray("tm1t4status");
  JsonArray tm1t5status = doc.createNestedArray("tm1t5status");
  JsonArray lightstatus = doc.createNestedArray("lightstatus");
  JsonArray cleanstatus = doc.createNestedArray("tm1cleanss");
  JsonArray tm1cleanstatus = doc.createNestedArray("tm1cleanstatus");



  lightstatus.add(lightsOn);
  if (_EEPROM.cleanMode) {
    cleanstatus.add("Enabled");
  } else {
    cleanstatus.add("Disabled");
  }

  tm1t1rt.add(_EEPROM.timerRuntimes[0]);
  tm1t2rt.add(_EEPROM.timerRuntimes[1]);
  tm1t3rt.add(_EEPROM.timerRuntimes[2]);
  tm1t4rt.add(_EEPROM.timerRuntimes[3]);
  tm1t5rt.add(_EEPROM.timerRuntimes[4]);
  tm1cleanrt.add(_EEPROM.timerRuntimes[5]);
  if (_EEPROM.enabled) {
    tm1SS.add("Enabled");
  } else {
    tm1SS.add("Disabled");
  }
  if (_EEPROM.timerEnabled[0]) {
    tm1t1s.add("Enabled");
  } else {
    tm1t1s.add("Disabled");
  }
  if (_EEPROM.timerEnabled[1]) {
    tm1t2s.add("Enabled");
  } else {
    tm1t2s.add("Disabled");
  }
  if (_EEPROM.timerEnabled[2]) {
    tm1t3s.add("Enabled");
  } else {
    tm1t3s.add("Disabled");
  }
  if (_EEPROM.timerEnabled[3]) {
    tm1t4s.add("Enabled");
  } else {
    tm1t4s.add("Disabled");
  }
  if (_EEPROM.timerEnabled[4]) {
    tm1t5s.add("Enabled");
  } else {
    tm1t5s.add("Disabled");
  }
  if (_EEPROM.timerEnabled[5]) {
    tm1cleans.add("Enabled");
  } else {
    tm1cleans.add("Disabled");
  }
  if (!_EEPROM.timerRunning[0]) {
    tm1t1status.add("Running");
    //  char a[] = {"Running"};
  } else {
    // char a[] = {"Not Running"};
    tm1t1status.add("Not Running");
  }
  if (!_EEPROM.timerRunning[1]) {
    tm1t2status.add("Running");
  } else {
    tm1t2status.add("Not Running");
  }
  if (!_EEPROM.timerRunning[2]) {
    tm1t3status.add("Running");
  } else {
    tm1t3status.add("Not Running");
  }
  if (!_EEPROM.timerRunning[3]) {
    tm1t4status.add("Running");
  } else {
    tm1t4status.add("Not Running");
  }
  if (!_EEPROM.timerRunning[4]) {
    tm1t5status.add("Running");
  } else {
    tm1t5status.add("Not Running");
  }
  if (!_EEPROM.timerRunning[5]) {
    tm1cleanstatus.add("Running");
  } else {
    tm1cleanstatus.add("Not Running");
  }
  char JSON[1000];
  serializeJson(doc, JSON);
  server.send(200, "text/plane", JSON);
}

void handlegettmjson2() {
  // yield();
  DynamicJsonDocument doc(600);
  JsonArray t1otdv = doc.createNestedArray("t1otdv");
  JsonArray t1offtdv = doc.createNestedArray("t1offtdv");
  JsonArray t2otdv = doc.createNestedArray("t2otdv");
  JsonArray t2offtdv = doc.createNestedArray("t2offtdv");
  JsonArray t3otdv = doc.createNestedArray("t3otdv");
  JsonArray t3offtdv = doc.createNestedArray("t3offtdv");
  JsonArray t4otdv = doc.createNestedArray("t4otdv");
  JsonArray t4offtdv = doc.createNestedArray("t4offtdv");
  JsonArray t1otnv = doc.createNestedArray("t1otnv");
  JsonArray t1offtnv = doc.createNestedArray("t1offtnv");
  JsonArray t2otnv = doc.createNestedArray("t2otnv");
  JsonArray t2offtnv = doc.createNestedArray("t2offtnv");
  JsonArray t3otnv = doc.createNestedArray("t3otnv");
  JsonArray t3offtnv = doc.createNestedArray("t3offtnv");
  JsonArray t4otnv = doc.createNestedArray("t4otnv");
  JsonArray t4offtnv = doc.createNestedArray("t4offtnv");

  t1otdv.add(_EEPROM.timerTimes[0][0]);
  t1offtdv.add(_EEPROM.timerTimes[0][1]);
  t2otdv.add(_EEPROM.timerTimes[1][0]);
  t2offtdv.add(_EEPROM.timerTimes[1][1]);
  t3otdv.add(_EEPROM.timerTimes[2][0]);
  t3offtdv.add(_EEPROM.timerTimes[2][1]);
  t4otdv.add(_EEPROM.timerTimes[3][0]);
  t4offtdv.add(_EEPROM.timerTimes[3][1]);

  t1otnv.add(_EEPROM.timerTimes[0][2]);
  t1offtnv.add(_EEPROM.timerTimes[0][3]);
  t2otnv.add(_EEPROM.timerTimes[1][2]);
  t2offtnv.add(_EEPROM.timerTimes[1][3]);
  t3otnv.add(_EEPROM.timerTimes[2][2]);
  t3offtnv.add(_EEPROM.timerTimes[2][3]);
  t4otnv.add(_EEPROM.timerTimes[3][2]);
  t4offtnv.add(_EEPROM.timerTimes[3][3]);



  char JSON[600];
  serializeJson(doc, JSON);
  server.send(200, "text/plane", JSON);
}

void handlegettmjson3() {
  // yield();
  DynamicJsonDocument doc(500);
  JsonArray labelt1 = doc.createNestedArray("labelt1");
  JsonArray labelt2 = doc.createNestedArray("labelt2");
  JsonArray labelt3 = doc.createNestedArray("labelt3");
  JsonArray labelt4 = doc.createNestedArray("labelt4");
  JsonArray labelt5 = doc.createNestedArray("labelt5");
  JsonArray labelt6 = doc.createNestedArray("labelt6");
  labelt1.add(_EEPROM.label[0]);
  labelt2.add(_EEPROM.label[1]);
  labelt3.add(_EEPROM.label[2]);
  labelt4.add(_EEPROM.label[3]);
  labelt5.add(_EEPROM.label[4]);
  labelt6.add(_EEPROM.label[5]);
  char JSON[500];
  serializeJson(doc, JSON);
  server.send(200, "text/plane", JSON);
}

void handlegettmjson4() {
  //  yield();
  DynamicJsonDocument doc(400);
  JsonArray cleanondurationv = doc.createNestedArray("cleanondurationv");
  JsonArray cleanoffdurationv = doc.createNestedArray("cleanoffdurationv");
  JsonArray disinfectdurationv = doc.createNestedArray("disinfectdurationv");

  JsonArray var3 = doc.createNestedArray("datetime");
  JsonArray t5otnv = doc.createNestedArray("t5otnv");
  JsonArray t5offtnv = doc.createNestedArray("t5offtnv");
  JsonArray t5otdv = doc.createNestedArray("t5otdv");
  JsonArray t5offtdv = doc.createNestedArray("t5offtdv");

  var3.add(str);
  cleanondurationv.add(_EEPROM.cleanOnTime);
  cleanoffdurationv.add(_EEPROM.cleanOffTime);
  disinfectdurationv.add(_EEPROM.cleanDisinfectTime);
  t5otnv.add(_EEPROM.timerTimes[4][2]);
  t5offtnv.add(_EEPROM.timerTimes[4][3]);
  t5otdv.add(_EEPROM.timerTimes[4][0]);
  t5offtdv.add(_EEPROM.timerTimes[4][1]);

  char JSON[400];
  serializeJson(doc, JSON);
  server.send(200, "text/plane", JSON);
}

Have you thought about using the ArduinoJson library?

1 Like

I already used arduinoJson. If you read my posts you would know that. I'm tired of asking the same question.

Seriously tho I asked this question a while ago I cant believe no one can answer it.

But i don't even care i will find out on my own eventually. I didn't claim to be an expert in this and dont care to be. sorry my questions are not up to your standards i thought this was a community forum.

Sorry, I got confused. You seem to be doing a huge amount of work to avoid using the Serialize and Deserialize features of the ArduinoJson library. I don't understand why you are doing things the way you are.

Your original question, well... problem, was an error when trying to manually serialize JSON by concatenating strings with '+':

That's because the '+' operator only works for concatenation on a String object. From the error, it looks like tm1runTime is not a String object. You discovered that you could convert character arrays to String to get the concatenation to work.

The ArduinoJson library can read a serialized JSON document directly from a web server and straight into a document without storing the serialized version in a buffer. It can also take your JSON document and send it to a web server in serialized form.

I'm confused as to why you are putting square brackets around every value. That makes your JSON document more than 50% larger since everything is a one-element array.

With the brackets:

// char* input;
// size_t inputLength; (optional)

StaticJsonDocument<2048> doc;

DeserializationError error = deserializeJson(doc, input, inputLength);

if (error) {
  Serial.print(F("deserializeJson() failed: "));
  Serial.println(error.f_str());
  return;
}

int tm1t1rt_0 = doc["tm1t1rt"][0]; // 0

int tm1t2rt_0 = doc["tm1t2rt"][0]; // 0

int tm1t3rt_0 = doc["tm1t3rt"][0]; // 0

int tm1t4rt_0 = doc["tm1t4rt"][0]; // 0

int tm1t5rt_0 = doc["tm1t5rt"][0]; // 0

int tm1cleanrt_0 = doc["tm1cleanrt"][0]; // 1

const char* tm1status_0 = doc["tm1status"][0]; // "Disabled"

const char* tm1t1s_0 = doc["tm1t1s"][0]; // "Enabled"

const char* tm1t2s_0 = doc["tm1t2s"][0]; // "Enabled"

const char* tm1t3s_0 = doc["tm1t3s"][0]; // "Enabled"

const char* tm1t4s_0 = doc["tm1t4s"][0]; // "Enabled"

const char* tm1t5s_0 = doc["tm1t5s"][0]; // "Enabled"

const char* tm1cleans_0 = doc["tm1cleans"][0]; // "Enabled"

const char* tm1t1status_0 = doc["tm1t1status"][0]; // "Not Running"

const char* tm1t2status_0 = doc["tm1t2status"][0]; // "Not Running"

const char* tm1t3status_0 = doc["tm1t3status"][0]; // "Not Running"

const char* tm1t4status_0 = doc["tm1t4status"][0]; // "Not Running"

const char* tm1t5status_0 = doc["tm1t5status"][0]; // "Not Running"

int lightstatus_0 = doc["lightstatus"][0]; // 0

const char* tm1cleanss_0 = doc["tm1cleanss"][0]; // "Enabled"

const char* tm1cleanstatus_0 = doc["tm1cleanstatus"][0]; // "Running"

const char* labelt1_0 = doc["labelt1"][0]; // "default"

const char* labelt2_0 = doc["labelt2"][0]; // "default"

const char* labelt3_0 = doc["labelt3"][0]; // "default"

const char* labelt4_0 = doc["labelt4"][0]; // "default"

const char* labelt5_0 = doc["labelt5"][0]; // "default"

const char* labelt6_0 = doc["labelt6"][0]; // "default"

int t1otdv_0 = doc["t1otdv"][0]; // 2000

long t1offtdv_0 = doc["t1offtdv"][0]; // 120000

int t1otnv_0 = doc["t1otnv"][0]; // 2000

long t1offtnv_0 = doc["t1offtnv"][0]; // 120000

int t2otdv_0 = doc["t2otdv"][0]; // 2000

long t2offtdv_0 = doc["t2offtdv"][0]; // 120000

int t2otnv_0 = doc["t2otnv"][0]; // 2000

long t2offtnv_0 = doc["t2offtnv"][0]; // 120000

int t3otdv_0 = doc["t3otdv"][0]; // 2000

long t3offtdv_0 = doc["t3offtdv"][0]; // 120000

int t3otnv_0 = doc["t3otnv"][0]; // 2000

long t3offtnv_0 = doc["t3offtnv"][0]; // 120000

int t4otdv_0 = doc["t4otdv"][0]; // 2000

long t4offtdv_0 = doc["t4offtdv"][0]; // 120000

int t4otnv_0 = doc["t4otnv"][0]; // 2000

long t4offtnv_0 = doc["t4offtnv"][0]; // 120000

int t5otdv_0 = doc["t5otdv"][0]; // 2000

long t5offtdv_0 = doc["t5offtdv"][0]; // 120000

int t5otnv_0 = doc["t5otnv"][0]; // 2000

long t5offtnv_0 = doc["t5offtnv"][0]; // 120000

int cleanondurationv_0 = doc["cleanondurationv"][0]; // 8000

int cleanoffdurationv_0 = doc["cleanoffdurationv"][0]; // 1000

long disinfectdurationv_0 = doc["disinfectdurationv"][0]; // 120000

const char* datetime_0 = doc["datetime"][0]; // "2021/8/5 4:33:15"

Without the brackets:

// char* input;
// size_t inputLength; (optional)

StaticJsonDocument<1024> doc;

DeserializationError error = deserializeJson(doc, input, inputLength);

if (error) {
  Serial.print(F("deserializeJson() failed: "));
  Serial.println(error.f_str());
  return;
}

int tm1t1rt = doc["tm1t1rt"]; // 0
int tm1t2rt = doc["tm1t2rt"]; // 0
int tm1t3rt = doc["tm1t3rt"]; // 0
int tm1t4rt = doc["tm1t4rt"]; // 0
int tm1t5rt = doc["tm1t5rt"]; // 0
int tm1cleanrt = doc["tm1cleanrt"]; // 1
const char* tm1status = doc["tm1status"]; // "Disabled"
const char* tm1t1s = doc["tm1t1s"]; // "Enabled"
const char* tm1t2s = doc["tm1t2s"]; // "Enabled"
const char* tm1t3s = doc["tm1t3s"]; // "Enabled"
const char* tm1t4s = doc["tm1t4s"]; // "Enabled"
const char* tm1t5s = doc["tm1t5s"]; // "Enabled"
const char* tm1cleans = doc["tm1cleans"]; // "Enabled"
const char* tm1t1status = doc["tm1t1status"]; // "Not Running"
const char* tm1t2status = doc["tm1t2status"]; // "Not Running"
const char* tm1t3status = doc["tm1t3status"]; // "Not Running"
const char* tm1t4status = doc["tm1t4status"]; // "Not Running"
const char* tm1t5status = doc["tm1t5status"]; // "Not Running"
int lightstatus = doc["lightstatus"]; // 0
const char* tm1cleanss = doc["tm1cleanss"]; // "Enabled"
const char* tm1cleanstatus = doc["tm1cleanstatus"]; // "Running"
const char* labelt1 = doc["labelt1"]; // "default"
const char* labelt2 = doc["labelt2"]; // "default"
const char* labelt3 = doc["labelt3"]; // "default"
const char* labelt4 = doc["labelt4"]; // "default"
const char* labelt5 = doc["labelt5"]; // "default"
const char* labelt6 = doc["labelt6"]; // "default"
int t1otdv = doc["t1otdv"]; // 2000
long t1offtdv = doc["t1offtdv"]; // 120000
int t1otnv = doc["t1otnv"]; // 2000
long t1offtnv = doc["t1offtnv"]; // 120000
int t2otdv = doc["t2otdv"]; // 2000
long t2offtdv = doc["t2offtdv"]; // 120000
int t2otnv = doc["t2otnv"]; // 2000
long t2offtnv = doc["t2offtnv"]; // 120000
int t3otdv = doc["t3otdv"]; // 2000
long t3offtdv = doc["t3offtdv"]; // 120000
int t3otnv = doc["t3otnv"]; // 2000
long t3offtnv = doc["t3offtnv"]; // 120000
int t4otdv = doc["t4otdv"]; // 2000
long t4offtdv = doc["t4offtdv"]; // 120000
int t4otnv = doc["t4otnv"]; // 2000
long t4offtnv = doc["t4offtnv"]; // 120000
int t5otdv = doc["t5otdv"]; // 2000
long t5offtdv = doc["t5offtdv"]; // 120000
int t5otnv = doc["t5otnv"]; // 2000
long t5offtnv = doc["t5offtnv"]; // 120000
int cleanondurationv = doc["cleanondurationv"]; // 8000
int cleanoffdurationv = doc["cleanoffdurationv"]; // 1000
long disinfectdurationv = doc["disinfectdurationv"]; // 120000
const char* datetime = doc["datetime"]; // "2021/8/5 4:33:15"

Now im really confused. what do you mean square brackets? your example of them does not look like my code. the problem i cant make a document with arduniojson larger than 1100byte otherwise it crashes. this makes me need to make 4-5 separate documents in order to get all the data from my server. this also mean 4-5 requests to the web server.

This string method i chose does not work stable either.

to be clear, im just requesting the json object from the esp8266, not sending to esp8266. What are my options here. can arduinojson document be larger than 1100 can i serialize 4 docs into 1 char array and send it as 1 request??

edit: you mean square brackets in the data. i didnt realize they were not necessary

Maybe using JSON arrays and booleans instead of strings will reduce the document size. In the code below the 'doc' is about 819 bytes (but they recommend 1024 to allow for actual data strings).

#include <ArduinoJson.h>

struct eeprom
{
  bool timerEnabled[5];
  bool timerRunning[5];
  unsigned long timerRuntimes[6];
  bool lightsOn;
  char * label[6];
  unsigned long timerTimes[4][4];
  bool cleanMode;
  int cleanOnTime;
  int cleanOffTime;
  int CleanDisinfectTime;
} _EEPROM;

void setup()
{
  Serial.begin(115200);
  delay(200);

  StaticJsonDocument<1024> doc;

  // Some arrays with 5 elements
  JsonArray timerEnabled = doc.createNestedArray("timerEnabled");
  JsonArray timerRunning = doc.createNestedArray("timerRunning");
  JsonArray timerRuntimes = doc.createNestedArray("timerRuntimes");

  for (int i = 0; i < 5; i++)
  {
    timerEnabled.add(_EEPROM.timerEnabled[i]);
    timerRunning.add(_EEPROM.timerEnabled[i]);
    timerRuntimes.add(_EEPROM.timerRuntimes[i]);
  }

  // An array with 6 elements
  JsonArray label = doc.createNestedArray("label");
  for (int i = 0; i < 6; i++)
  {
    label.add(_EEPROM.label[i]);
  }

  JsonArray timerTimes = doc.createNestedArray("timerTimes");
  JsonArray timerTimesRows[4];

  for (int row = 0; row < 4; row++)
  {
    timerTimesRows[row] = timerTimes.createNestedArray();
    for (int col = 0; col < 4; col++)
    {
      timerTimesRows[row].add(_EEPROM.timerTimes[row][col]);
    }
  }

  doc["cleanOnTime"] = _EEPROM.cleanOnTime;
  doc["cleanOffTime"] = _EEPROM.cleanOffTime;
  doc["CleanDisinfectTime"] = _EEPROM.CleanDisinfectTime;
  doc["datetime"] = "2021/8/5 4:33:15";

  serializeJsonPretty(doc, Serial);
}

void loop() {}

/*
 * Results:
 *   
{
  "timerEnabled": [
    false,
    false,
    false,
    false,
    false
  ],
  "timerRunning": [
    false,
    false,
    false,
    false,
    false
  ],
  "timerRuntimes": [
    0,
    0,
    0,
    0,
    0
  ],
  "label": [
    null,
    null,
    null,
    null,
    null,
    null
  ],
  "timerTimes": [
    [
      0,
      0,
      0,
      0
    ],
    [
      0,
      0,
      0,
      0
    ],
    [
      0,
      0,
      0,
      0
    ],
    [
      0,
      0,
      0,
      0
    ]
  ],
  "cleanOnTime": 0,
  "cleanOffTime": 0,
  "CleanDisinfectTime": 0,
  "datetime": "2021/8/5 4:33:15"
}

*/
1 Like

Thankyou. i will have to edit my javascript for json arrays but i think that's manageable. That's much better than the 4 "1100 byte" docs i was using. I have use the arduinojson size calculator before to tell me the size of my json but the tools would tell me like 300bytes but i had to still use at east twice that otherwise it didn't work right.

what exactly is limiting arduinojson docs to 1100 bytes anyways. is the the ram of my microcontroller? why can't i create a 2048 or 4096 byte document??

I did a Google search for "arduinojson 1100 limit" and the only reference I found was this thread. Is the limit documented somewhere that I did not find?

I should explain better. When I try to create arduinoJson staticdocument over 1100 bytes and request it from the tcp http server my esp8266 just crashes. My esp is the standard I think 80kb of ram.

I have not found a way to check how much stack is remaining when my program is running. There's 37000 byte left on the heap. I dont know if the documents are destroyed after the json function runs or not.

All I know is I can send 10 documents 1024 bytes one after another for months no problem but 1150 bytes and it crashes pretty much right away. I know String is dynamic and can fragment the heap but I still dont know if I should expect problems creating my json object via String object..

I know the cpu crashes before the TCP server send the data so I'm 99% sure it's not some limitation of tcp http server

Edit: apparently I'm wrong about ram size of my chip.

RAM size <45kB (In station Mode, when connected to AP, the available space of heap+data is about 40+KB )

But I also read differently so who knows right? Wemos d1 mini