I've looked at the docs, the issues, and how to use the FIFO map. These examples are creating the JSON through assignment to the new type.
I have my JSON data in a regular old char *. How can I use the FIFO trick to keep it ordered when creating the nlohmann::json?
The only way I see to get from my char * to nlohmann::json is nlohmann::json::parse(), but then the FIFO map doesn't work - or am I missing something?
Thanks!
Could you post a small example with the error message?
Sure. It doesn't produce an error - it just doesn't keep it sorted because parse doesn't know about the my_json type::
// A workaround to give to use fifo_map as map, we are just ignoring the 'less' compare
template<class K, class V, class dummy_compare, class A>
using my_workaround_fifo_map = nlohmann::fifo_map<K, V, nlohmann::fifo_map_compare<K>, A>;
using my_json = nlohmann::basic_json<my_workaround_fifo_map>;
...
{
// The data comes from some other source as a char *
const char *cData = R"({ "foo":"bar", "blat" : { "ding" : {}, "baz" : {} } })";
// How do I keep it ordered when deserializing the json?
my_json object = nlohmann::json::parse( cData );
std::cout << object.dump() << std::endl;
}
Result:
{"blat":{"baz":{},"ding":{}},"foo":"bar"}
You need to use my_json::parse() instead of nlohmann::json::parse().
Ahhhh!!!!
I'm obviously not a template guy, but I see it now :-)
Thank you.