ArduinoJson ... named Multi dimensional arrays ?

HI,

I currently have this, what I would like instead of 1 to 7, I would like the array number ...

0 to become Temperature
1 to become Humidity ... etc.

Is this possible in ArduinoJson ?
I think this is called Multi dimensional arrays ?

Thanks

03

You mean something like this?
No, it's not a multi dimensional array, it'a JSON encoded string.
Yes, ArduinoJson ca do this (It's exactly his job)

{
  "Temperature": 23.5,
  "Humidity": 45,
  "Whatever": 999
}

Hi Thanks,

I do know how do that :slightly_smiling_face:

Here is an example i found online if the type of thing I want ..

{
"firstName": "John",
"lastName": "Smith",
"isAlive": true,
"age": 25,
"address": {
"streetAddress": "21 2nd Street",
"city": "New York",
"state": "NY",
"postalCode": "10021-3100"
},
"phoneNumbers": [
{
"type": "home",
"number": "212 555-1234"
},
{
"type": "office",
"number": "646 555-4567"
}
],
"children": [],
"spouse": null
}

The ArduinoJson it's a really well made library!
If you take a look at the author's website you will find all the necessary documentation (an ebook is also available, but for a fee)

In any case, there is the excellent ArduinoJson Assistan tool online where you can insert your JSON and it produces the code necessary to obtain it.

For example for the JSON you posted before this is the output provided:

JsonDocument doc;

doc["firstName"] = "John";
doc["lastName"] = "Smith";
doc["isAlive"] = true;
doc["age"] = 25;

JsonObject address = doc["address"].to<JsonObject>();
address["streetAddress"] = "21 2nd Street";
address["city"] = "New York";
address["state"] = "NY";
address["postalCode"] = "10021-3100";

JsonArray phoneNumbers = doc["phoneNumbers"].to<JsonArray>();

JsonObject phoneNumbers_0 = phoneNumbers.add<JsonObject>();
phoneNumbers_0["type"] = "home";
phoneNumbers_0["number"] = "212 555-1234";

JsonObject phoneNumbers_1 = phoneNumbers.add<JsonObject>();
phoneNumbers_1["type"] = "office";
phoneNumbers_1["number"] = "646 555-4567";

JsonArray children = doc["children"].to<JsonArray>();
doc["spouse"] = nullptr;

String output;

doc.shrinkToFit();  // optional

serializeJson(doc, output);

Hi,

Thanks, I will try that :slightly_smiling_face:

Here is an example that might give you some ideas.

This is json data I send from a pc via ethernet to an open source plc, mkr zero compatible.

[{"hx":75,"hn":60,"hd":10,"cx":0,"cn":0,"cd":0,"al":0,"st":1,"hw":0,"de":1},
{"hx":60,"hn":50,"hd":5,"cx":0,"cn":0,"cd":0,"al":0,"st":1,"hw":0,"de":4},
{"hx":160,"hn":110,"hd":20,"cx":0,"cn":0,"cd":0,"al":0,"st":1,"hw":0,"de":3},
{"hx":0,"hn":0,"hd":0,"cx":0,"cn":0,"cd":0,"al":0,"st":0,"hw":0,"de":0}]

this is how I parse it after deserialization by arduinojson.
As you can see rows are 0 based.

for (uint8_t i = 1; i < 5; i++)  //channels start at 1. 
{
		thHtgMx[1][i] = doc[i - 1]["hx"];
		EEPROM.write(ea, thHtgMx[1][i]);
		ea += 1;

		thHtgMn[1][i] = doc[i - 1]["hn"];
		EEPROM.write(ea, thHtgMn[1][i]);
		ea += 1;

		thHtgDif[1][i] = doc[i - 1]["hd"];
		EEPROM.write(ea, thHtgDif[1][i]);
		ea += 1;

		thClgMx[1][i] = doc[i - 1]["cx"];
		EEPROM.write(ea, thClgMx[1][i]);
		ea += 1;

		thClgMn[1][i] = doc[i - 1]["cn"];
		EEPROM.write(ea, thClgMn[1][i]);
		ea += 1;

		thClgDif[1][i] = doc[i - 1]["cd"];
		EEPROM.write(ea, thClgDif[1][i]);
		ea += 1;

		thAlarm[1][i] = doc[i - 1]["al"];
		EEPROM.write(ea, thAlarm[1][i]);
		ea += 1;

		thSteam[1][i] = doc[i - 1]["st"];
		EEPROM.write(ea, thSteam[1][i]);
		ea += 1;

		thHotWtr[1][i] = doc[i - 1]["hw"];
		EEPROM.write(ea, thHotWtr[1][i]);
		ea += 1;

		thDesc[1][i] = doc[i - 1]["de"];
		EEPROM.write(ea, thDesc[1][i]);
		ea += 1;
}

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