1

I'm trying to figure out what the best way to clone rapidjson is. I'm seeing a few good ideas online, which differ greatly.

  1. There's the example Milo gives in his documentation (deep copy milo), which is just like the deep copy example in tutorial.md in rapidjson. However, this is for an oversimplified, one Value json. For large, multi-type, json, iterating would be complicated, and I'm not seeing a good example.

  2. There is newDocument copy which has an example I like, but someone commented parsing is slow, but for a large rapidjson example, iterating over the entire set would take long too. Plus, the <0> or other syntax appear wrong. There is no type given.

    static void copyDocument(rapidjson::Document & newDocument,   rapidjson::Document & copiedDocument) {
        rapidjson::StringBuffer strbuf;
        rapidjson::Writer<rapidjson::StringBuffer> writer(strbuf);
        newDocument.Accept(writer);
        std::string str = strbuf.GetString();
        copiedDocument.Parse<0>(str.c_str());
    }
    
  3. Apparently there's a DeepCopy patch, but I'm not sure how to use it, or if it's in my version of rapidjson (1.1.0). I haven't had luck using GenericMember yet. We are using DOM. I can't use an unofficial release of rapidjson because the license would be different and it would deviate from mainstream releases of rapidjson.

For libjson, we used to do a shallow copy, like &rhs, but I'm looking for suggestions, and possibly an example of using the DeepCopy patch if it's in 1.1.0.

Community
  • 1
  • 1
Michele
  • 3,617
  • 12
  • 47
  • 81
  • 1
    What are you trying to ask? This reads as off-topic ("help me pick an app to use"), but as it is, you're not asking anything. – Nic Feb 15 '17 at 14:41
  • I'm looking for suggestions. Someone said parsing again in second example is too slow. But I think that doing the copy of each Value and iterating over a large json set and putting in a new doc would be slow too like Milos says to do. Is the DeepCopy patch in 1.1.0? If it is, how would I use it? Is there a good use example, other than looking at the API to figure it out? – Michele Feb 15 '17 at 14:47
  • My advice is to try the `rapidjson` version from `https://github.com/rjeczalik/rapidjson` which is the answer to your point #2 (and it is supposed to have a DeepCopy patch). Use `CMake` to generate a MakeFile / project file to build. – drescherjm Feb 15 '17 at 14:47
  • I don't think I can use un-released versions. It might not fall under licensing for original rapidjson. If it was in an official release I think I could though. That was my #3 above. – Michele Feb 15 '17 at 14:49
  • Ah, I see. I was reading this as "help me find a library to do this", but you're asking "how can I do this task; here are some external resources that do it, but they all have problems." I'd suggest rephrasing your question so that it's more obvious you aren't looking for a library or tool. – Nic Feb 15 '17 at 15:15
  • I think it's valid to discuss the difference between #1 and #2 for a large json set, and which is more efficient and why. Also, if anyone could tell me if DeepCopy patch was ever officially released into rapidjson, which it doesn't appear that it is, that seems valid also. – Michele Feb 15 '17 at 15:17

0 Answers0