Thanks @linev. (I incorrectly thought I could import any arbitrary JSON and it would get populated into a blank TObject, but this is wrong, my bad).
BTW when using nlohmann::json, I get this error on Windows with VS 2022 + root_v6.32.12:
In file included from libtest dictionary payload:5:
In file included from E:/projects/src\Instrument.h:4:
In file included from C:/Program Files/root_v6.32.12\include\nlohmann/json.hpp:2440:
In file included from C:\Program Files (x86)\Microsoft Visual Studio\2022\BuildTools\VC\Tools\MSVC\14.43.34808\include\cassert:9:
In file included from C:\Program Files (x86)\Windows Kits\10\Include\10.0.19041.0\ucrt\assert.h:12:
C:\Program Files (x86)\Windows Kits\10\Include\10.0.19041.0\ucrt\corecrt.h:205:12: error: redefinition of '_CrtEnableIf<true, _Ty>'
struct _CrtEnableIf<true, _Ty>
^~~~~~~~~~~~~~~~~~~~~~~
One possible reason for the problem - if you are using nlohmann/json.hpp version which does not match with used by ROOT. If you run ROOT script (without compilation), just try:
root [0] auto res = nlohmann::json::parse("{ \"abc\": 7}");
root [1] std::cout << res["abc"] << std::endl;
7
I use nlohmann/json.hpp that is shipped with root (not another version that I would have downloaded).
I just tried root.exe and then:
root [0] #include <nlohmann/json.hpp>
immediately gives
In file included from ROOT_prompt_0:1:
In file included from C:/Program Files/root_v6.32.12\include\nlohmann/json.hpp:2440:
In file included from C:\Program Files (x86)\Microsoft Visual Studio\2022\BuildTools\VC\Tools\MSVC\14.43.34808\include\cassert:9:
In file included from C:\Program Files (x86)\Windows Kits\10\Include\10.0.19041.0\ucrt\assert.h:12:
C:\Program Files (x86)\Windows Kits\10\Include\10.0.19041.0\ucrt\corecrt.h:205:12: error: redefinition of '_CrtEnableIf<true, _Ty>'
struct _CrtEnableIf<true, _Ty>
^~~~~~~~~~~~~~~~~~~~~~~
With my “hacked” version with //#include <cassert> commented off, those error messages aren’t present and this works:
auto res = nlohmann::json::parse("{ \"abc\": 7}");
std::cout << res["abc"] << std::endl;
Thanks. On Windows, @bellenot, do you think I should modify json.hpp by commenting off the #include <cassert>: if you have time to look, can you reproduce this problem too, when launching root.exe and doing: