I'd agree with the suggestion that what you're seeing probably stems from failing to open the file correctly. For one obvious example of how to temporarily eliminate that problem so you can test the rest of your code, you might consider reading the data in from an istringstream
:
#include <iostream>
#include <iomanip>
#include <nlohmann/json.hpp>
#include <sstream>
using json = nlohmann::json;
using namespace std;
int main(int argc, const char * argv[]) {
std::istringstream i(R"(
{"n" : 2,
"x" : [[1,2],
[0,4]]}
)");
json j;
i >> j;
// Format and display the data:
std::cout << std::setw(4) << j << "\n";
}
As an aside, also note how you're normally expected to include the header. You give the compiler <json-install-directory>/include
as the directory to search, and your code uses #include <nlohmann/json.hpp>
to include the header.