Skip to main content
1 of 2
Juraj
  • 18.2k
  • 4
  • 30
  • 49

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

Juraj
  • 18.2k
  • 4
  • 30
  • 49