Files
json/docs/mkdocs/docs/api/basic_json_document/owns_source.md
Niels Lohmann 54455afa40 Document json_document and json_view
- API pages for basic_json_document and basic_json_view, one per member,
  and for the four aliases, each with an example
- features/json_view.md: the problem the view solves, ownership and
  lifetime, what matches basic_json::parse() and what differs, and when
  to choose json, ordered_json, SAX, or the view
- the examples show why one would use the view, not only how: borrowed
  vs. owned input, reading a few fields and materializing one subtree,
  reusing a document across many messages
- registered in the mkdocs navigation, llms.txt, the docset, the
  exceptions page (out_of_range.416), architecture.md, the integration
  page, and the README; the yyjson credit is added to the README and
  license.md

Signed-off-by: Niels Lohmann <mail@nlohmann.me>
2026-09-29 14:02:43 +02:00

1.2 KiB

nlohmann::basic_json_document::owns_source

bool owns_source() const noexcept;

Returns whether the document holds its own copy of the parsed text, as opposed to borrowing the caller's buffer.

Return value

#!cpp true if the document owns the text returned by source(), #!cpp false if it borrows it (or if the document is discarded).

Exception safety

No-throw guarantee: this function never throws exceptions.

Complexity

Constant.

Notes

See the ownership table on parse for which inputs are borrowed and which are owned. A borrowed document (#!cpp owns_source() == false) is only valid while the buffer it was parsed from is still alive.

Examples

??? example

```cpp
--8<-- "examples/basic_json_document__owns_source.cpp"
```

Output:

```json
--8<-- "examples/basic_json_document__owns_source.output"
```

See also

  • parse - deserialize from a compatible input
  • parse_copy - deserialize a copy of a compatible input, always owned
  • source - the parsed text

Version history

  • Added in version 3.13.0.