Closed amassalha closed 3 months ago
Apologies for the delay, just getting to this one.
jsoncons::json json_array = jsoncons::json::array();
is roughly equivalent to (the preferred)
jsoncons::json json_array{jsoncons::json_array_arg};
If you really want to use a json::array
directly rather than through a json
, I would suggest writing that as
auto json_array = jsoncons::json::array();
json_array.push_back("value1");
json_array.push_back(42);
json_array.push_back(jsoncons::json::object({ {"key", "value"} }));
jsoncons::json json{ std::move(json_array)}; // move to avoid copying
std::ofstream outfile(filename);
outfile << jsoncons::pretty_print(json);
A json::array
is not a json
, but is copyable and movable into a json
. json::array
and json::object
are really implementation detail for json
.
This code compilation fails:
but when I change 'auto' with jsoncons::json, it works. seems array is not a json: