Files
json/docs/mkdocs/docs/api/basic_json_view/end.md
Niels Lohmann 2f087c6b73 Document element access, lookup, and iteration of json_view
- API pages for operator[], at, front, back, find, contains, count,
  begin, end, cbegin, cend, items, and type_name of basic_json_view,
  linked both ways with the basic_json pages
- the feature page and size() describe document order and duplicate
  keys
- the examples show when the view helps: reading a few fields of a large
  text, probing optional members, and members in source order

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

1.5 KiB

nlohmann::basic_json_view::end

iterator end() const noexcept;

Returns an iterator to one past the last element of an array, one past the last member value of an object, in document order -- see begin(). A primitive value iterates as a range of one element (itself); #!json null and a discarded view iterate as an empty range, so #!cpp begin() == end() for them.

Return value

Iterator one past the last element.

Exception safety

No-throw guarantee: this function never throws exceptions.

Complexity

Constant.

Notes

#!cpp iterator is a forward iterator: unlike BasicJsonType::iterator, it cannot be decremented, so there is no way to reach the last element by stepping back from end(). Use back() instead.

Examples

??? example

The example below scans a (possibly large) array of readings for the first one over a threshold, stopping the
loop at `end()` as soon as one is found. Only the matching reading, if any, is ever materialized.

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

Output:

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

See also

  • begin - returns an iterator to the first element
  • cend - returns a const iterator to one past the last element
  • BasicJsonType::end - the corresponding function of basic_json

Version history

  • Added in version 3.13.0.