Files
json/api/ordered_json_document.md
T
2026-10-21 10:31:00 +00:00

1.6 KiB

nlohmann::ordered_json_document

Defined in header <nlohmann/json_view.hpp>

using ordered_json_document = basic_json_document<ordered_json>;

This type is a basic_json_document of the ordered_json specialization: materialize() on one of its views preserves the insertion order of object keys, instead of sorting them like json_document does.

Examples

??? example

The example below demonstrates how `ordered_json_document` preserves the insertion order of object keys when
materializing.

```cpp
#include <iostream>
#include <nlohmann/json_view.hpp>

using ordered_json_document = nlohmann::ordered_json_document;

int main()
{
    // ordered_json_document is basic_json_document<nlohmann::ordered_json>:
    // materialize() preserves the insertion (source) order of object keys,
    // instead of sorting them like json_document does
    ordered_json_document doc = ordered_json_document::parse(R"({"z": 1, "a": 2, "m": 3})");
    std::cout << doc.root().materialize().dump() << '\n';
}

```

Output:

```json
{"z":1,"a":2,"m":3}

```

See also

Version history

Since version 3.13.0.