template<template< typename U, typename V, typename... Args > class ObjectType = std::map, template< typename U, typename... Args > class ArrayType = std::vector, class StringType = std::string, class BooleanType = bool, class NumberIntegerType = std::int64_t, class NumberUnsignedType = std::uint64_t, class NumberFloatType = double, template< typename U > class AllocatorType = std::allocator, template< typename T, typename SFINAE=void > class JSONSerializer = adl_serializer, class BinaryType = std::vector<std::uint8_t>>
std::ostream & operator<< |
( |
std::ostream & |
o, |
|
|
const basic_json< ObjectType, ArrayType, StringType, BooleanType, NumberIntegerType, NumberUnsignedType, NumberFloatType, AllocatorType, JSONSerializer, BinaryType > & |
j |
|
) |
| |
|
friend |
serialize to stream
Serialize the given JSON value j to the output stream o. The JSON value will be serialized using the dump member function.
- The indentation of the output can be controlled with the member variable
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 dump(4)
.
- The indentation character can be controlled with the member variable
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.
- Parameters
-
[in,out] | o | stream to serialize to |
[in] | j | JSON value to serialize |
- Returns
- the stream o
- Exceptions
-
type_error.316 | if a string stored inside the JSON value is not UTF-8 encoded |
@complexity Linear.
@liveexample{The example below shows the serialization with different parameters to width
to adjust the indentation level.,operator_serialize}
- Since
- version 1.0.0; indentation character added in version 3.0.0
Definition at line 24515 of file json.hpp.
24516 {
24517
24518 const bool pretty_print = o.width() > 0;
24519 const auto indentation = pretty_print ? o.width() : 0;
24520
24521 o.width(0);
24522
24523 serializer s(detail::output_adapter<char>(o), o.fill());
24524 s.dump(j, pretty_print, false, static_cast<unsigned int>(indentation));
24525 return o;
24526 }