mirror of
https://github.com/nlohmann/json.git
synced 2026-11-09 22:12:32 +00:00
deploy: 6f01030c4e
This commit is contained in:
1 parent
cf8df97ba7
commit
eeea067a72
566 files changed
+15370
-2688
No files matched your search
@@ -65,7 +65,7 @@ Chained access
|
||||
|
||||
Duplicate keys: the first member wins
|
||||
|
||||
If the source text has an object with a duplicate key, `operator[]` (and [`at`](https://json.nlohmann.me/api/basic_json_view/at/index.md), [`find`](https://json.nlohmann.me/api/basic_json_view/find/index.md), [`contains`](https://json.nlohmann.me/api/basic_json_view/contains/index.md), [`value`](https://json.nlohmann.me/api/basic_json_view/value/index.md), and JSON pointer resolution) all resolve to the *first* member with that key, because a lookup can stop as soon as it finds a match. This is different from [`materialize()`](https://json.nlohmann.me/api/basic_json_view/materialize/index.md) (and [`BasicJsonType::parse()`](https://json.nlohmann.me/api/basic_json/parse/index.md)), which replay every member in order and so keep the *last* value for a repeated key, so `v["a"]` and `v.materialize()["a"]` can differ. To get the value `parse()` would give, use [`materialize()`](https://json.nlohmann.me/api/basic_json_view/materialize/index.md) or iterate the members with [`items()`](https://json.nlohmann.me/api/basic_json_view/items/index.md) and keep the last match. The key hash index of a larger object (128 members or more) leads to the first member of a key as well. [`begin()`](https://json.nlohmann.me/api/basic_json_view/begin/index.md)/[`end()`](https://json.nlohmann.me/api/basic_json_view/end/index.md) and [`items()`](https://json.nlohmann.me/api/basic_json_view/items/index.md) iterate over *all* members, including duplicates, in document order. See [Duplicate keys](https://json.nlohmann.me/features/json_view/#duplicate-keys) and [`size()`](https://json.nlohmann.me/api/basic_json_view/size/#notes).
|
||||
If the source text has an object with a duplicate key, `operator[]` (and [`at`](https://json.nlohmann.me/api/basic_json_view/at/index.md), [`find`](https://json.nlohmann.me/api/basic_json_view/find/index.md), [`contains`](https://json.nlohmann.me/api/basic_json_view/contains/index.md), [`value`](https://json.nlohmann.me/api/basic_json_view/value/index.md), and JSON pointer resolution) all resolve to the *first* member with that key, because a lookup can stop as soon as it finds a match. This is different from [`materialize()`](https://json.nlohmann.me/api/basic_json_view/materialize/index.md) (and [`BasicJsonType::parse()`](https://json.nlohmann.me/api/basic_json/parse/index.md)), which replay every member in order and so keep the *last* value for a repeated key, so `v["a"]` and `v.materialize()["a"]` can differ. To get the value `parse()` would give, use [`materialize()`](https://json.nlohmann.me/api/basic_json_view/materialize/index.md) or iterate the members with [`items()`](https://json.nlohmann.me/api/basic_json_view/items/index.md) and keep the last match. The key hash index of a larger object (128 members or more) leads to the first member of a key as well. [`begin()`](https://json.nlohmann.me/api/basic_json_view/begin/index.md)/[`end()`](https://json.nlohmann.me/api/basic_json_view/end/index.md) and [`items()`](https://json.nlohmann.me/api/basic_json_view/items/index.md) iterate over *all* members, including duplicates, in document order. See [Duplicate keys](https://json.nlohmann.me/features/json_view/differences/#duplicate-keys) and [`size()`](https://json.nlohmann.me/api/basic_json_view/size/#notes).
|
||||
|
||||
JSON pointer resolution
|
||||
|
||||
|
||||
Reference in new issue
Block a user