title: How to recursive create QJsonObject's without copies
body: <p>Might relate to <a href="https://stackoverflow.com/questions/17034336/how-to-change-qjsonobject-value-in-a-qjson-hierarchy-without-using-copies/29361151">How to change QJsonObject value in a QJson hierarchy without using copies?</a>, but the answer is basically, it doesn't work, maybe things have changed since then.
  Given is the following signature:</p>
  <pre><code>void addToJson(const QStringList&amp; path, QJsonObject&amp; target, const QJsonObject&amp; object)
  </code></pre>
  <p>It should build a JSON object based on the <code>path</code> and add <code>object</code>, e.g:</p>
  <pre><code>  path: obj,obj2,obj3
    -&gt;
        &quot;obj&quot;: {
          &quot;obj2&quot;: {
            &quot;obj3&quot;: {
            }
          }
        }
  </code></pre>
  <p><code>object</code> would be added to obj3.</p>
  <p>Current implementation is:</p>
  <pre><code>void addToJson(const QStringList&amp; path, QJsonObject&amp; target, const QJsonObject&amp; object)
  {
      if(path.isEmpty())
      {
          target = object;
          return;
      }
  
      QString objName = path.first();
  
      QJsonObject tmpObj = target[objName].toObject();
      addToJson(path.mid(1), tmpObj, object);
      target[objName] = tmpObj;
  }
  </code></pre>
  <p>Can it be written, to avoid the copies (basically you would have a lot of deep copies in each iteration)?</p>
  <p>The <code>[]</code> operator gives you a <code>QJsonValueRef</code>, what is good, but if you want to add something to it, you would need to convert it to a <code>QJsonObject</code> again and not a <code>QJsonValueRef</code>, which breaks everything.</p>