A quick alternative to JsonCpp that allows you to copy / modify the capabilities of Json objects?

JsonCpp is slow. And the code is pretty dirty.

Is there an alternative that is faster, cleaner, and supports things like:

Json::Value val, copy; val["newMember"] = 100; val["newMember2"] = "hello"; copy = val; val["newMember2"] = "bye"; assert(val["newMember"] == copy["newMember"]); assert(val["newMember2"] != copy["newMember2"]); 

JsonCpp supports code similar to the above.

I tried quickjson , which is very fast, but unfortunately it does not support copying Json values.

Any alternative? Bonus point for tests.

+2
source share
1 answer

After some time searching for the โ€œdocumentationโ€ I finally found a good way to copy JSON objects using quickjson, which is very convenient:

 rapidjson::Document doc; // This is the base document that you got from parsing etc rapidjson::Value& v = doc["newMember"]; // newMember = 100 assert(v.GetInt() == 100); rapidjson::Document copy; doc.Accept(copy); // The accept meachnism is the same as used in parsing, but for copying assert(copy["newMember"].GetInt() == doc["newMember"].GetInt()) 

Explicit copying has one advantage: it makes you think clearly when you use links or potentially unnecessary copies.

+4
source

Source: https://habr.com/ru/post/1443724/


All Articles