#include "nlohmann/json.hpp"
#include <iostream>
#include <map>
#include <string>
using json = nlohmann::json;
struct Data
{
std::string a;
std::string b;
};
void from_json(const json& j, Data& data)
{
j["a"].get_to(data.a);
j["b"].get_to(data.b);
}
int main()
{
// create a JSON object
json j =
{
{"1", {
{"a", "testa_1"},
{"b", "testa_1"}
}},
{"2", {
{"a", "testa_2"},
{"b", "testb_2"}
}},
{"3", {
{"a", "testa_3"},
{"b", "testb_3"}
}},
};
std::map<std::string, Data> data;
j.get_to(data);
for (const auto& p : data)
{
std::cout << p.first << " -> " << p.second.a << ", " << p.second.b << std::endl;
}
}
It looks like the change to fix #1292 (11fecc2) causes a regression when converting to a container std::pair with a non-trivial type. I didn't see a unit test that covers this case.
Example code that show the failure:
https://wandbox.org/permlink/BVgyd1o4MW60bqvS