0
 static bool equalJson(Value &json1, Value &json2, Value &reference, bool a) {
    for (Value::ConstMemberIterator itr = reference.MemberBegin(); itr <= reference.MemberEnd(); itr++) {

        if (itr->value.GetType() == kArrayType) {
            for (auto itr1 = itr->value.Begin(); itr1 != itr->value.End(); itr1++) {
                // cout<<itr->name.GetString()<<endl;//Gets the keys or members that are arrays on the Top Level
                switch (itr1->GetType()) {
                    case kObjectType:

                        for (auto itr = itr1->MemberBegin(); itr != itr1->MemberEnd(); itr++) {
                            // cout<<itr->name.GetString()<<endl;//Elements(keys) of the arrays
                            if (itr->value.GetType() == kArrayType) {
                                //cout<<itr->name.GetString()<<endl;//The keys inside the Top level array that are having sub arrays
                               Document doc;

                                //doc.CopyFrom(itr->name, doc.GetAllocator());
                                doc.CopyFrom(itr->value, doc.GetAllocator());

                                StringBuffer s;
                                Writer<StringBuffer> w(s);
                                doc.Accept(w);
                                cout << s.GetString() << endl;

                                // test::equalJson(json1,json2,doc,a);



                            }
                        }
                }
            }

       }

I have a format something like this..

 "object_array1": [
 {"key": null },
 {"key": null },
 {"key": null }
]


What i have in the itr->value is

[
 {"key": null },
 {"key": null },
 {"key": null }
]


I would like to have some thing like this.....in the Document doc;


 {    
 "object_array1": [
 {"key": null },
 {"key": null },
 {"key": null }
]

 }


In order to acheive this i did try...

  rapidjson::Value t_object(rapidjson::kObjectType);
  t_object.CopyFrom(itr->value, doc.GetAllocator());
  rapidjson::Value dir_name_key(itr->name.GetString(), 
  doc.GetAllocator());
  doc.AddMember(dir_name_key, t_object, doc.GetAllocator());

but it's still an array

Your help will be highly appreciated. My reference json file:

{
"array": [
null
],
"boolean": null,
"null": null,
"object": {
"a": null,
"c": null,
"e": null
 },
"number": null,

"deep_nested_array": [
    {"object_array1": [
 {"key": null },
 {"key": null },
 {"key": null }
 ]}
  ],
 "object_array": [
 {"key": null },
 {"key": null },
 {"key": null }
 ],
 "string": null
  }

Main aim is to use recursion to loop inside n number of nested arrays or objects( as the arrays in the json will be random) to get each key and utilize it. while recursing i need that valid format of data as I showed in the above description to be stored it in doc to pass in the function

 static bool equalJson(Value &json1, Value &json2, Value &reference, bool a) {

  while recursion:
  equaljson(json1,json2,doc,a);

If you have better suggestion than this it will be a great help.Thank you

Pheonix
  • 1
  • 2
  • 1
    Giving part of the code you have would help others to answer your question – KSTN Apr 21 '18 at 06:27
  • Boost Property Tree is **not** a JSON library. So it's likely not what you want anyways. In particular it has problems representing JSON arrays. ¯\\_(ツ)_/¯ Regardless of that, see [some of my answers]() for ways to recursively query/enumerate property trees – sehe Apr 21 '18 at 12:48
  • Actually, this is about as duplicate as it gets https://stackoverflow.com/questions/30105711/boostptree-find-or-how-to-access-deep-arrays-c/30125315#30125315 – sehe Apr 21 '18 at 12:48
  • Yes property tree is just an alternative but I am looking solution in rapidjson . As said I will be clarifying the question – Pheonix Apr 21 '18 at 14:27
  • What is it that the `equalJson` function will do? Exactly. The name implies that it'll be pretty straightforward. By the way your question has all the hallmarks of very bad questions. (_Very_ bad. Being unclear about the intent, a formatting disaster, code in screenshots (!) screenshots off-site...) – sehe Apr 22 '18 at 20:08
  • As the name suggests equal json checks equality, as the parser cannot iterate to deeper array or objects , I intend to use recursion for the purposes . the problem I am facing is to recurse the specific keys that has nested array or objects – Pheonix Apr 23 '18 at 02:36
  • https://github.com/Tencent/rapidjson/issues/1187 . This describes the problem that I am facing . Hope someone can help me with that – Pheonix Apr 24 '18 at 05:12

0 Answers0