"Data" is apparently a const int, and you're trying to return a non-const reference to it. That's not allowed (as the compiler so kindly tells you). Make "Data" non-const, stick with a const T& return type, or don't return a reference. Those are basically your choices. ...
Here is the same example with files: // read a JSON file std::ifstream i("file.json"); json j; i >> j; // write prettified JSON to another file std::ofstream o("pretty.json"); o << std::setw(4) << j << std::endl; Please note that setting the exception bit for ...