How to create a JSON array?

Hi,

I want to create a JSON array using Arduino UNO. I was able to create a JSON format for three sensor values (code below); however, I need to put all JSON values in an array format like the format below :

[
{
"Vacuum RPM" :900,
"Vacuum Height" :2,
"Tractor Speed" :5
}
]

How can I edit the code below for this purpose?

I appreciate any help in advance.
Abbas

#include <ArduinoJson.h>
StaticJsonDocument<1000> doc; 

void setup()
{
  Serial.begin( 9600 ); 
}

void loop()
{
  int rpm = 900;
  int Measured_Height= 2;
  int speed = 5;
  
  doc["RPM"] = rpm;
  doc["Height"] = Measured_Height;
  doc["Speed"] = speed;
  serializeJsonPretty(doc, Serial);
  Serial.println(); 
  delay(1000);
}

The ArduinoJson.org "Assistant" says to get that JSON, use:

StaticJsonDocument<64> doc;

JsonObject doc_0 = doc.createNestedObject();
doc_0["Vacuum RPM"] = 900;
doc_0["Vacuum Height"] = 2;
doc_0["Tractor Speed"] = 5;

serializeJson(doc, output);

Hi johnwasser,

Thank you so much for your help. It works now,

To help everyone, please mark @johnwasser's post as solved with the :white_check_mark: button

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