In C++ you can create a template function like the library defines the. (The ArduinoJson []
operator is a template too.)
#include <ArduinoJson.h>
StaticJsonDocument<512> tempJDOC;
template <typename T>
void setValue(const char *key, T value){
tempJDOC[key]=value;tempJDOC[key] = value;
}
void setup() {
Serial.begin(115200);
setValue("a", 5);
setValue("b", "xyz");
serializeJson(tempJDOC, Serial);
}
void loop() {
}
the compiler will create function based on this template for every different type you use as second parameter in your sketch