How to write down lines JSON format in IDE

Hello guys!

I have a project that send a json format but I don't know how to write down lines.
It is a long chars ( {"DeviceID":[{"SlaveID":2,"Voltage":[0,0,0,0],"Current":[0,0,0,0],"PF":0,"Freq":0,"P":0,"Q":0,"S":0,"E":0},{"SlaveID":3,"Voltage":[0,0,0,0],"Current":[0,0,0,0],"PF":0,"Freq":0,"P":0,"Q":0,"S":0,"E":0}]} ).
I want to write down each element in the string like:
{"DeviceID":[
{"SlaveID":2,"Voltage":[0,0,0,0],"Current":[0,0,0,0],"PF":0,"Freq":0,"P":0,"Q":0,"S":0,"E":0},
{"SlaveID":3,"Voltage":[0,0,0,0],"Current":[0,0,0,0],"PF":0,"Freq":0,"P":0,"Q":0,"S":0,"E":0}]}
Can I do that? Thanks for attention.

This is my code
`DynamicJsonDocument PM1(300);

PM1["SlaveID"] = 2;
PM1["Voltage"][0] = v1;
PM1["Voltage"][1] = v2;
PM1["Voltage"][2] = v3;
PM1["Voltage"][3] = v;
PM1["Current"][0] = i1;
PM1["Current"][1] = i2;
PM1["Current"][2] = i3;
PM1["Current"][3] = i;
PM1["PF"] = PF;
PM1["Freq"] = freq;
PM1["P"] = P;
PM1["Q"] = Q;
PM1["S"] = S;
PM1["E"] = E;
DynamicJsonDocument PM2(300);
PM2["SlaveID"] = 3;
PM2["Voltage"][0] = pm2_v1;
PM2["Voltage"][1] = pm2_v2;
PM2["Voltage"][2] = pm2_v3;
PM2["Voltage"][3] = pm2_v;
PM2["Current"][0] = pm2_i1;
PM2["Current"][1] = pm2_i2;
PM2["Current"][2] = pm2_i3;
PM2["Current"][3] = pm2_i;
PM2["PF"] = 0;
PM2["Freq"] = 0;
PM2["P"] = 0;
PM2["Q"] = 0;
PM2["S"] = 0;
PM2["E"] = 0;
DynamicJsonDocument ReadPM(600);
ReadPM["DeviceID"][0] = PM1;
ReadPM["DeviceID"][1] = PM2;
//serializeJson(Voltage, Serial);
char JSONmessageBuffer[1024];
serializeJson(ReadPM, JSONmessageBuffer);
Serial.println(JSONmessageBuffer);
`

What do you want to do with these lines, say, in a C/C++ program for Arduino?

Sorry I dont good at English. I want to write down the line in my Json String.
It can be :
DeviceID:[
{.........................},
{.........................}
]

@huyenhuan001 If you need to use the double quote character ( " ) in your string you must prefix it with the C escape character ( \ ).

So if you wanted your variable command to have a value of

"Current":[0,0,0,0]

You would declare as

char command[] = "\"Current\":[0,0,0,0]";

Thank you very much!!

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