Can I return ofJson from a function? Should I use a ofJson Variable

I am making a class containing this function,

ofJson APILoad::urlLoader(string url, string file)
Response = ofLoadURL(url);

myBuffer =;

ResponseStr = myBuffer.getData();

cout << "  " << ResponseStr;

FILE *fp;

fp = fopen(file.c_str, "w");

fprintf(fp, "%s", ResponseStr.c_str());



json = ofLoadJson(file);



According to the question above, is the correct format?

Lots of documentation missing from ofJson it seems, any good resources?

Hi, there is no need to write to a file, unless you want it to be that way.

ofJson APILoad::urlLoader(string url)
    Response = ofLoadURL(url);
    try {
        return ofJson::parse(;
    catch (ofJson::parse_error& ex)
        return ofJson();

ofJson is just a name alias for nlohmann::json which has a very good documentation.

1 Like