This commit is contained in:
nlohmann
2026-10-03 05:43:12 +00:00
parent 2aaa1d24ef
commit a410b4f40f
741 changed files with 8115 additions and 2252 deletions
@@ -4,7 +4,7 @@
Elements in a JSON object and a JSON array can be accessed via [`operator[]`](https://json.nlohmann.me/api/basic_json/operator%5B%5D/index.md) similar to a `std::map` and a `std::vector`, respectively.
Read access
Example: read access
Consider the following JSON value:
@@ -29,7 +29,7 @@ Assume the value is parsed to a `json` variable `j`.
The return value is a reference, so it can modify the original value. In case the passed object key is non-existing, a `null` value is inserted which can immediately be overwritten.
Write access
Example: write access
```
j["name"] = "John Smith";
@@ -49,7 +49,7 @@ This code produces the following JSON value:
When accessing an invalid index (i.e., an index greater than or equal to the array size), the JSON array is resized such that the passed index is the new maximal index. Intermediate values are filled with `null`.
Filling up arrays with `null` values
Example: filling up arrays with `null` values
```
j["hobbies"][0] = "running";
@@ -86,7 +86,7 @@ Danger
- It is **undefined behavior** to access a const object with a non-existing key.
- It is **undefined behavior** to access a const array with an invalid index.
- In debug mode, an **assertion** will fire in both cases. You can disable assertions by defining the preprocessor symbol `NDEBUG` or redefine the macro [`JSON_ASSERT(x)`](https://json.nlohmann.me/features/macros/#json_assertx). See the documentation on [runtime assertions](https://json.nlohmann.me/features/assertions/index.md) for more information.
- In debug mode, an **assertion** will fire in both cases. You can disable assertions by defining the preprocessor symbol `NDEBUG` or redefine the macro [`JSON_ASSERT(x)`](https://json.nlohmann.me/api/macros/json_assert/index.md). See the documentation on [runtime assertions](https://json.nlohmann.me/features/assertions/index.md) for more information.
Exceptions
@@ -94,7 +94,7 @@ Exceptions
## Performance: reserving array capacity
There is no public `reserve(count)` member on `basic_json` for pre-allocating array capacity. If you are building a large array incrementally (e.g., via repeated `push_back()`) and know its final size ahead of time, you can reserve capacity via `get_ref()` to access the underlying `array_t` directly:
There is no public `reserve(count)` member on `basic_json` for pre-allocating array capacity. If you are building a large array incrementally (e.g., via repeated [`push_back()`](https://json.nlohmann.me/api/basic_json/push_back/index.md)) and know its final size ahead of time, you can reserve capacity via [`get_ref()`](https://json.nlohmann.me/api/basic_json/get_ref/index.md) to access the underlying `array_t` directly:
```
json j = json::array();