user48730: I'm trying to create a function that enters a key/value into a JSON file.
But, since value can be an int or char, I don't want to create 2 functions for each type.
Is there a way ?
void setValue(char *key, char* value){
        StaticJsonDocument<512> tempJDOC;
        tempJDOC[key]=value;
}

EDIT1
#ifndef myJSON_h
#define myJSON_h

#include "Arduino.h"
#include <ArduinoJson.h>
#include "FS.h"


class myJSON
{
private:
bool _useSerial=false;
char _filename[30];

public:
char *ver="myJSON_v1.1";
myJSON(char *filename, bool useserial=false);

bool file_exists();
bool file_remove();
bool format ();
bool FS_ok();

void saveJSON2file(JsonDocument& _doc);
void readJSON_file(JsonDocument& _doc);

void printJSON(JsonDocument& _doc);
void PrettyprintJSON(JsonDocument& _doc);

const char *getValue (char *key);

template <class T>
void setValue(const char *key, T value);
//void setValue(const char *key, char *value);

};
#endif

EDIT2
#ifndef myJSON_h
#define myJSON_h

#include "Arduino.h"
#include <ArduinoJson.h>
#include "FS.h"

#define LOG_LENGTH 4
#define DOC_SIZE 512

template <class T> // . <---- line added
class myJSON
{
private:
bool _useSerial=false;
char _filename[30];

public:
char *ver="myJSON_v1.1";
myJSON(char *filename, bool useserial=false);

bool file_exists();
bool file_remove();
bool format ();
bool FS_ok();

void saveJSON2file(JsonDocument& _doc);
void readJSON_file(JsonDocument& _doc);

void printJSON(JsonDocument& _doc);
void PrettyprintJSON(JsonDocument& _doc);

const char *getValue (const char *key);
void removeValue(const char *key);
// void setValue(const char *key, char *value); <--- comment out
void updateArray(char* array_key, int val);
void printFile();
void setValue(const char *key, T value); <---- Added

};
#endif

and in .cpp file :
void myJSON::setValue(const char *key, T value){
        StaticJsonDocument<512> tempJDOC;
        myJSON::readJSON_file(tempJDOC);
        tempJDOC[key]=value;
        myJSON::saveJSON2file(tempJDOC);
        myJSON::PrettyprintJSON(tempJDOC);
}


user7508: The short answer is “no, it's not possible”. You will have to use two
different functions. These two functions can share the same name, using
function overloading. You can even have the compiler
write these functions for you, based on a template you provide, as shown
in Juraj's answer. These language features help provide the illusion of
there being a single function. But it's just an illusion, albeit a
useful one that helps with program readability. At the fundamental
level, you still have two different functions.

user37622: In C++ you can create a template function. (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;
}

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

48730: <p>I'm trying to create a function that enters a key/value into a JSON file.</p>

<p>But, since value can be an <code>int</code> or <code>char</code>, I don't want to create 2 functions for each type.</p>

<p>Is there a way ?</p>

<pre><code>void setValue(char *key, char* value){
        StaticJsonDocument&lt;512&gt; tempJDOC;
        tempJDOC[key]=value;
}
</code></pre>

<p><strong>EDIT1</strong></p>

<pre><code>#ifndef myJSON_h
#define myJSON_h

#include "Arduino.h"
#include &lt;ArduinoJson.h&gt;
#include "FS.h"


class myJSON
{
private:
bool _useSerial=false;
char _filename[30];

public:
char *ver="myJSON_v1.1";
myJSON(char *filename, bool useserial=false);

bool file_exists();
bool file_remove();
bool format ();
bool FS_ok();

void saveJSON2file(JsonDocument&amp; _doc);
void readJSON_file(JsonDocument&amp; _doc);

void printJSON(JsonDocument&amp; _doc);
void PrettyprintJSON(JsonDocument&amp; _doc);

const char *getValue (char *key);

template &lt;class T&gt;
void setValue(const char *key, T value);
//void setValue(const char *key, char *value);

};
#endif
</code></pre>

<p><strong>EDIT2</strong></p>

<pre><code>#ifndef myJSON_h
#define myJSON_h

#include "Arduino.h"
#include &lt;ArduinoJson.h&gt;
#include "FS.h"

#define LOG_LENGTH 4
#define DOC_SIZE 512

template &lt;class T&gt; // . &lt;---- line added
class myJSON
{
private:
bool _useSerial=false;
char _filename[30];

public:
char *ver="myJSON_v1.1";
myJSON(char *filename, bool useserial=false);

bool file_exists();
bool file_remove();
bool format ();
bool FS_ok();

void saveJSON2file(JsonDocument&amp; _doc);
void readJSON_file(JsonDocument&amp; _doc);

void printJSON(JsonDocument&amp; _doc);
void PrettyprintJSON(JsonDocument&amp; _doc);

const char *getValue (const char *key);
void removeValue(const char *key);
// void setValue(const char *key, char *value); &lt;--- comment out
void updateArray(char* array_key, int val);
void printFile();
void setValue(const char *key, T value); &lt;---- Added

};
#endif
</code></pre>

<p>and in .cpp file :</p>

<pre><code>void myJSON::setValue(const char *key, T value){
        StaticJsonDocument&lt;512&gt; tempJDOC;
        myJSON::readJSON_file(tempJDOC);
        tempJDOC[key]=value;
        myJSON::saveJSON2file(tempJDOC);
        myJSON::PrettyprintJSON(tempJDOC);
}
</code></pre>
 7508: <p>The short answer is “no, it's not possible”. You will have to use two
different functions. These two functions can share the same name, using
<a href="https://www.programiz.com/cpp-programming/function-overloading" rel="nofollow noreferrer">function overloading</a>. You can even have the compiler
write these functions for you, based on a template you provide, as shown
in Juraj's answer. These language features help provide the illusion of
there being a single function. But it's just an illusion, albeit a
useful one that helps with program readability. At the fundamental
level, you still have two different functions.</p>
 37622: <p>In C++ you can create a template function. (The ArduinoJson <code>[]</code> operator is a template too.)</p>

<pre><code>#include &lt;ArduinoJson.h&gt;

StaticJsonDocument&lt;512&gt; tempJDOC;

template &lt;typename T&gt;
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() {
}
</code></pre>

<p>the compiler will create function based on this template for every different type you use as second parameter in your sketch</p>
