rapidjson - recursively change key value with nested field
<p>I have a Json record with nested object and object arrays, the keys in those field contain spaces, I want to change all spaces to <code>_</code>, so I have to iterate all keys in the json object.</p>

<p>My idea is to write a depth first search to iterate all nested keys using <code>ConstMemberIterator</code>, my question is how can I change the key by given its iterator?</p>

<p>The example below represents my idea:</p>

<pre><code>void DFSReplaceSpaceInKeys(Value::ConstMemberIterator&amp; itr) {
    // Replace space in nested key
    std::string s(itr-&gt;name.GetString());
    std::replace(s.begin(), s.end(), ' ', '_');
    // set new string to key
    itr-&gt;name.SetString(s, ?.GetAllocator());  // &lt;----- How can I get the document allocator?
    std::cout &lt;&lt; "new key: " &lt;&lt; itr-&gt;name.GetString() &lt;&lt; std::endl;
    // recursive call in DFS
    if (itr-&gt;value.GetType() == Type::kObjectType) {
        DFSReplaceSpaceInKeys(itr-&gt;value.GetObject().MemberBegin());
    }
}
</code></pre>

<p>A Json record example:</p>

<pre><code>{
   "a": {"b": [{"c": [...]}, {...}]
}
</code></pre>