With nlohmann::json
an object can be parsed using a couple different expressions:
type x = json;
type x; x = json.get<type>();
However, type x; x = json;
doesn't work, because that would require adding a new assignment operator for type
.
I find myself needing to use expression (2) more often then expression (1). This can get quite annoying, especially if type
is something complicated.
In a few cases, I defined
template <typename U>
void convert(const json& j, U& x) { x = j.get<U>(); }
But it would be nice if get
had an overload taking a reference as an argument, so that the following would be possible.
type x;
json.get(x);
Is there already a function that does that, that just has a different name? I couldn't find one in the documentation.
Edit: I've submitted an issue on GitHub.
Edit 2: An alternative to the get
function, T& get_to(T&)
, will be included in release 3.3.0.