title: iterate and retrieve nested object in JSON using rapidjson
body: <p>I am parsing a <code>JSON</code> structure which is similar as follows</p>
  
  <pre><code>{
      "item1" : "value1"
      "item2" : "value2"
      // ...
      "itemn" : {
          "outernestedItem1" : {
              "innerNestedItem1" : "valuen1"
              "innerNestedItem2" : "valuen2"
          }
          // ....
          "outernestedItemn" : {
              "innerNestedItem1" : "valuen1"
              "innerNestedItem2" : "valuen2"
          }
      }
  }
  </code></pre>
  
  <p>The number of outer nested items is not fixed, so I was iterating using iterator from rapidjson, inner-nested objects variables are fixed, so I can get access to them using [].</p>
  
  <pre><code>const rapidjson::Value&amp; itemn = document["itemn"];
  for (rapidjson::Value::ConstMemberIterator itr = itemn.MemberBegin();
  itr != itemn.MemberEnd(); ++itr)
  {
      rapidjson::StringBuffer sb;
      rapidjson::Writer&lt;rapidjson::StringBuffer&gt; writer( sb );
      itr-&gt;value.Accept(writer);
  
      std::cout &lt;&lt; sb["innerNestedItem1"].GetString();
      std::cout &lt;&lt; sb["innerNestedItem2"].GetString();
  }
  </code></pre>
  
  <p>but [] is not allowed with sb(string buffer), any idea how can I do this?</p>
  
  <p>Edit1:
  I did it in very inefficient way, but just sharing the solution, so it might help someone to come up with efficient solution.</p>
  
  <pre><code>const rapidjson::Value&amp; itemn = document["itemn"];
  for (rapidjson::Value::ConstMemberIterator itr = itemn.MemberBegin();
  itr != itemn.MemberEnd(); ++itr)
  {
      rapidjson::StringBuffer sb;
      rapidjson::Writer&lt;rapidjson::StringBuffer&gt; writer( sb );
      itr-&gt;value.Accept(writer);
  
      //changed from here onwards
      rapidjson::Document for_outer_nested_item;
      std::string temp = sb.GetString();
      char buffer2[100000];
      strcpy_s(buffer2, temp.c_str());
      for_outer_nested_item.ParseInsitu(buffer2);
      std::cout &lt;&lt; executive_command["innerNestedItem1"].GetString() &lt;&lt; std::endl;
      std::cout &lt;&lt; executive_command["innerNestedItem2"].GetString() &lt;&lt; std::endl;
  }
  </code></pre>