I'm new to ArduinoJSON - so perhaps it is a newbie's question.... but I wish to pass a StaticJsonDocument into a function as a parameter ( later on it should be implemented in a library ).
exmaple below shows test_1 what I wish to obtain, but by duplicating StaticJsonDocument, which I don't want to do.
How can test_1 should be written (as I tried in test_2)?
#include <ArduinoJson.h>
StaticJsonDocument<200> doc;
void createJSON() {
doc["sensor"] = "gps";
doc["time"] = 1351824120;
JsonArray data = doc.createNestedArray("data");
data.add(48.756080);
data.add(2.302038);
// Generate the minified JSON and send it to the Serial port.
serializeJson(doc, Serial);
Serial.println("JSON is created:");
// Generate the prettified JSON and send it to the Serial port.
serializeJsonPretty(doc, Serial);
}
bool test_1(StaticJsonDocument<100> _doc){
serializeJson(_doc, Serial);
return true;
}
bool test2(const JsonObject& _doc){
Serial.println("HI");
serializeJson(_doc, Serial);
}
void setup() {
Serial.begin(9600);
createJSON();
test_1(doc);
}
void loop() {
// not used in this example
}