title: Qt modifying a JSON file
body: <p>I need to be able to read in an existing JSON file, make modifications to it (such as replacing, removing and adding objects, arrays and key-value pairs), and then write the file out again.</p>
  
  <p>I have am trying to read and write to a JSON file with these contents:</p>
  
  <pre><code>{
      "array": [
          {
              "name": "Channel",
              "default": 1
  
          },
          {
              "name": "Size",
              "default": 457
          }
      ]
  }
  </code></pre>
  
  <p>I am reading the file in successfully, but failing to make any changes to it using the following code:</p>
  
  <pre><code>QFile File("/path/to/myfile.json");
  File.open(QIODevice::ReadOnly | QIODevice::Text);
  
  QJsonParseError JsonParseError;
  QJsonDocument JsonDocument = QJsonDocument::fromJson(File.readAll(), &amp;JsonParseError);
  
  File.close();
  
  QJsonObject RootObject = JsonDocument.object();
  QJsonArray Array = RootObject.value("array").toArray();
  
  QJsonObject ElementOneObject = Array.at(0).toObject();
  
  ElementOneObject.insert("key", QJsonValue(QString("value")));
  ElementOneObject.insert("name", QJsonValue(QString("David")));
  
  File.open(QFile::WriteOnly | QFile::Text | QFile::Truncate);
  File.write(JsonDocument.toJson());
  File.close();
  </code></pre>
  
  <p>I am expecting to see the first element of the array to have a new name of "David" and a new key-value pair like <code>"key" : "value"</code>. The contents of the file are identical after this code has run. I know the file has been written out, because the ordering of the key-value pairs has been changed to be ordered by the keys sorted into alphabetic order.</p>
  
  <p>How do I get the file to refelct the changes I have tried to make?</p>