#include <ArduinoJson.h>
struct Integer {
int Default;
int Value;
int Max;
int Min;
String Name;
String PlaceHolder;
String Type;
};
struct DeviceStatus {
bool isConnected;
int batteryLevel;
};
void setup() {
Serial.begin(115200);
// Create instances of the structs
Integer Id;
Id.Value=55;
Id.Max=100;
Id.Min=10;
Id.Name="Device Id";
Id.PlaceHolder="Device Id Mandatory";
Id.Type="input";
DeviceStatus deviceStatus;
deviceStatus.isConnected = true;
deviceStatus.batteryLevel = 80;
// Create a JSON document
DynamicJsonDocument jsonDoc(512);
// Convert the structs to JSON
JsonObject sensorObj = jsonDoc.createNestedObject("sensorData");
sensorObj["Value"] = Id.Value;
sensorObj["Max"]=Id.Max;
sensorObj["Min"]=Id.Min;
sensorObj["Name"]=Id.Name;
sensorObj["PlaceHolder"]=Id.PlaceHolder;
sensorObj["Type"]=Id.Type;
JsonObject statusObj = jsonDoc.createNestedObject("deviceStatus");
statusObj["isConnected"] = deviceStatus.isConnected;
statusObj["batteryLevel"] = deviceStatus.batteryLevel;
// Serialize the JSON document to a string
String jsonString;
serializeJson(jsonDoc, jsonString);
// Print the JSON string
Serial.println(jsonString);
}
void loop() {
// Your code here
}