This commit is contained in:
nlohmann committed 2026-10-12 07:35:31 +00:00
1 parent 79119509a9
commit 22fba27145
555 files changed
+17342 -1394

No files matched your search

+21 -2
View File
@@ -117,13 +117,32 @@ matter. For instance, `nlohmann::json::with_object_t<nlohmann::ordered_map>` is
only when `nlohmann::ordered_json` is used.
```cpp
--8<-- "examples/with_t.cpp"
#include <iostream>
#include <map>
#include <nlohmann/json.hpp>
// a JSON type that stores objects in a std::map (which keeps keys sorted)
// instead of the default ordered associative container
using sorted_json = nlohmann::json::with_object_t<std::map>;
int main()
{
sorted_json j;
j["c"] = 1;
j["a"] = 2;
j["b"] = 3;
// keys are sorted, because std::map is used to store the object
std::cout << j.dump() << std::endl;
}
```
Output:
```json
--8<-- "examples/with_t.output"
{"a":2,"b":3,"c":1}
```
## See also