Files
json/docs/mkdocs
Niels Lohmann 1db091b784 Document and test the lifetime of string_view members decoded from a json_view
A struct with a std::string_view member defined via NLOHMANN_DEFINE_TYPE_*
decodes from a json_view without a copy: the member points into the source
text, or, for a string with escape sequences, into the buffer of decoded
strings of the document. It is valid while the document is alive and, for a
document that borrows its text, while that text is.

The feature page now says so, including that the same struct compiles with
json::parse(text).get<T>() and then points into the temporary json value.
The new test checks where plain and escaped members point and that they stay
readable while the document and a borrowed source text are alive. It does not
read dangling memory.

Signed-off-by: Niels Lohmann <mail@nlohmann.me>
2026-10-30 22:41:47 +01:00
..