json/doc/mkdocs/docs/api/basic_json/to_string.md
2021-11-04 22:36:11 +01:00

857 B

to_string(basic_json)

template <typename BasicJsonType>
std::string to_string(const BasicJsonType& j)

This function implements a user-defined to_string for JSON objects.

Template parameters

BasicJsonType
a specialization of basic_json

Return value

string containing the serialization of the JSON value

Exceptions

Throws type_error.316 if a string stored inside the JSON value is not UTF-8 encoded

Exception safety

Strong guarantee: if an exception is thrown, there are no changes to any JSON value.

Complexity

Linear.

Possible implementation

template <typename BasicJsonType>
std::string to_string(const BasicJsonType& j)
{
    return j.dump();
}

See also

Version history

Added in version 3.7.0.