Reading Json file with root


I am trying to read a json file using the library nlohmann-json. My code is the following:

#include "/usr/local/Cellar/nlohmann-json/3.11.2/include/nlohmann/json.hpp"
#include <iostream>
void ReadJson()
    std::ifstream param_file("params.json");
    nlohmann::json Parameters = nlohmann::json::parse(param_file);

Which throws the following error:

libc++abi: terminating with uncaught exception of type cling::InvalidDerefException: Trying to access a pointer that points to an invalid memory address.

I do not know if it is relevant, but when trying to include nlohmann-json I first tried with:
#include "nlohmann/json.hpp"

But root did not recognize it, so I had to install the library separately and write the full path to the library location.

Thanks in advance.

Please read tips for efficient and successful posting and posting code

ROOT Version: 6.28/06
Platform: macOS Monterrey 12.6.3
Compiler: Not Provided

Maybe add after this line, for security:
if(!param_file.good()) return;

But tI do want to read the file, so the execution of that line is needed.

That lines adds a security: if the file name is incorrect or not found, it will exit instead of crashing. So you have to fix the filename or path so that it finds it correctly.

Actually, the file is found correctly (param_file.good()) returns true so I believe the issue must be coming from the nlohmann-json library.

Mmm maybe try to share the json file with us, or try to debug it yourself with:

The content of the json file is as simple as:

  "a": 1

I have tried to run this very same code on another laptop and it does work, so I guess it might be related to the ROOT installation. By the way, I am not allowed to modified the original post anymore, but there is a mistake with the ROOT version, it is 6.26/06.