std::ostream& operator<<(std::ostream& o, const basic_json_view& v);
Not available when JSON_NO_IO is defined.
Serializes the given view v to the output stream o, using dump -- exactly as #!cpp operator<<(std::ostream&, const basic_json&) does for a basic_json value.
width of the output stream o. For instance, using the manipulator std::setw(4) on o sets the indentation level to 4, and the serialization result is the same as calling #!cpp v.dump(4). A width of 0 or less (the default) selects the most compact representation, as #!cpp v.dump(-1) does.fill of the output stream o. For instance, the manipulator std::setfill('\t') sets indentation to use a tab character rather than the default space character.basic_json, o's width is reset to 0 after this call, whether or not it was greater than 0 before.Numbers are always written as #!cpp v.dump() writes them by default, i.e. as with number_format::shortest; there is no way to select #!cpp number_format::source through the stream.
o (in, out) : stream to write to
v (in) : view to serialize
the stream o
May throw #!cpp std::bad_alloc, propagated from dump. Unlike #!cpp operator<<(std::ostream&, const basic_json&), there is no UTF-8 decoding step that could throw type_error.316, and no error_handler to choose between -- see the Exceptions of dump.
Linear, as dump.
??? example
The example below writes one record out of a larger batch straight to a log stream -- compact for a one-line
entry, and pretty-printed with `std::setw`/`std::setfill` for a readable dump -- without ever building a
`BasicJsonType` value for the record, or for the rest of the batch.
```cpp
#include <iostream>
#include <iomanip>
#include <nlohmann/json_view.hpp>
using json_document = nlohmann::json_document;
using json_view = nlohmann::json_view;
int main()
{
// one order out of a large incoming batch -- write it straight to a log
// stream without ever building a basic_json value for it, or for the
// rest of the batch
const json_document doc = json_document::parse(R"(
[{"id": 1, "item": "cable"}, {"id": 2, "item": "adapter"}]
)");
const json_view orders = doc.root();
// compact, for a one-line log entry
std::cout << orders[1] << '\n';
// std::setw sets the indentation level, exactly as for basic_json
std::cout << std::setw(2) << orders[1] << "\n\n";
// std::setfill changes the indentation character
std::cout << std::setw(1) << std::setfill('\t') << orders[1] << '\n';
}
```
Output:
```json
{"id":2,"item":"adapter"}
{
"id": 2,
"item": "adapter"
}
{
"id": 2,
"item": "adapter"
}
```
operator<<(std::ostream&) - the corresponding operator for basic_jsonJSON_NO_IO - switch off functions relying on certain C++ I/O headers