you can create a template function like the library defines the []
operator
#include <ArduinoJson.h>
StaticJsonDocument<512> tempJDOC;
template <typename T>
void setValue(const char *key, T 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