Files
json/docs/mkdocs/docs/api/basic_json_view/get_to.md
Niels Lohmann 9856da2561 Document values and JSON pointers of json_view
- API pages for get, get_to, get_string, number_token, and value of
  basic_json_view; JSON pointer overloads of operator[], at, and
  contains; links both ways with the basic_json pages
- the feature page describes which conversions copy nothing
- the examples show when the view helps: strings without copies, numbers
  exactly as written, and paths into a large text

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

1.2 KiB

nlohmann::basic_json_view::get_to

template<typename T>
T& get_to(T& v) const;

Converts the value to T and assigns it to v. Equivalent to

v = get<T>();
return v;

Template parameters

T
the type to convert the value to

Parameters

v (out)
the variable to store the converted value in

Return value

v, allowing calls to chain

Exception safety

Strong exception safety: if an exception is thrown, v is not modified.

Exceptions

Whatever get<T>() throws for the same value and T.

Complexity

Whatever get<T>() has for the same T.

Examples

??? example

The example below reads several fields of a service configuration directly into existing variables, then uses
the returned reference to fold the `#!cpp host`/`#!cpp port` pair into a single string in the same expression.

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

Output:

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

See also

Version history

  • Added in version 3.13.0.