Skip to content

nlohmann::ordered_json

using ordered_json = basic_json<ordered_map>;

This type preserves the insertion order of object keys.

Examples

Example

The example below demonstrates how ordered_json preserves the insertion order of object keys.

#include <iostream>
#include <nlohmann/json.hpp>

using ordered_json = nlohmann::ordered_json;

int main()
{
    ordered_json j;
    j["one"] = 1;
    j["two"] = 2;
    j["three"] = 3;

    std::cout << j.dump(2) << '\n';
}

Output:

{
  "one": 1,
  "two": 2,
  "three": 3
}

See also

Version history

Since version 3.9.0.


Last update: May 17, 2022