Files
json/docs/mkdocs/docs/api/basic_json_document/node_count.md
T
Niels Lohmann d9a71e7bc5 Document the node index of json_view on the architecture page
A new section describes the 16-byte node: its fields, how integers,
floats, and object members are stored, how views navigate without
pointers, and a worked example. The feature page and the pages of
basic_json_document and node_count link to it where they mention the
16 bytes.

Signed-off-by: Niels Lohmann <mail@nlohmann.me>
2026-09-30 20:58:48 +02:00

1.1 KiB

nlohmann::basic_json_document::node_count

std::size_t node_count() const noexcept;

Returns the number of entries in the document's flat index.

Return value

The number of index entries: one per value (of any type, at any nesting depth) plus one per object key. 0 for a discarded document.

Exception safety

No-throw guarantee: this function never throws exceptions.

Complexity

Constant.

Notes

Each index entry is 16 bytes, so #!cpp node_count() * 16 is the size of the index itself (part, but not all, of memory_usage(), which also counts decoded strings and, for an owned document, the text).

Examples

??? example

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

Output:

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

See also

Version history

  • Added in version 3.13.0.