mirror of
https://github.com/nlohmann/json.git
synced 2026-10-31 09:55:42 +00:00
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>