mirror of
https://github.com/nlohmann/json.git
synced 2026-10-07 15:07:13 +00:00
19 lines
450 B
C++
19 lines
450 B
C++
#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;
|
|
}
|