title: Appending new data to an existing JSON file
body: <p>I have searched high and low, and far and wide for a solution to this, and have spent the last few weeks trying to implement my own solution, but I just can't come up with anything.</p>
  
  <p>I would greatly appreciate any help at all!</p>
  
  <p>I have a file, which looks like, (file.json):</p>
  
  <pre><code>{
    "Expense": {
      "Name": "OneTel Mobile Bill",
      "Amount": "39.90",
      "Due": "28/12/2011",
      "Recurrence": "1 Months",
      "Paid": "0",
      "LastPaid": "01/01/2002"
    }
  }
  </code></pre>
  
  <p>And in my app, when I create a new 'Expense', I want to append that new Expense to this existing JSON file, so it looks like so:</p>
  
  <pre><code>{
    "Expense": {
      "Name": "OneTel Mobile Bill",
      "Amount": "39.90",
      "Due": "28/12/2011",
      "Recurrence": "1 Months",
      "Paid": "0",
      "LastPaid": "01/01/2002"
    },
    "Expense": {
      "Name": "Loan Repayment",
      "Amount": "50.00",
      "Due": "08/03/2012",
      "Recurrence": "3 Months",
      "Paid": "0",
      "LastPaid": "08/12/2011"
    }
  }
  </code></pre>
  
  <p>And this is how I am creating the JSON and writing to the file:</p>
  
  <pre><code>async public void WriteToFile(string type, string data)
  {
      file = await folder.GetFileAsync(file.FileName);
      IRandomAccessStream writestream = await file.OpenAsync(FileAccessMode.ReadWrite);
  
  
      IOutputStream outputstream = writestream.GetOutputStreamAt(0);
      DataWriter datawriter = new DataWriter(outputstream);
      datawriter.WriteString(data);
  
      await datawriter.StoreAsync();
      outputstream.FlushAsync().Start();
  }
  
  private void CreateExpenseButton_Click(object sender, RoutedEventArgs e)
  {
      //Create the Json file and save it with WriteToFile();
      JObject jobject =
          new JObject(
              new JProperty("Expense",
                  new JObject(
                      new JProperty("Name", NameTextBox.Text),
                      new JProperty("Amount", AmountTextBox.Text),
                      new JProperty("Due", DueTextBox.Text),
                      new JProperty("Recurrence", EveryTextBox.Text + " " + EveryComboBox.SelectionBoxItem),
                      new JProperty("Paid", "0"),
                      new JProperty("LastPaid", "Never")
                             )
                           )
                     );
      try
      {
          WriteToFile(Expenses, jobject.ToString());
  
          // Close the flyout now.
          this.Visibility = Windows.UI.Xaml.Visibility.Collapsed;
      }
      catch (Exception exception)
      {
          Debug.Write(exception.Message);
  
      }
  }
  </code></pre>
  
  <p>I am using the Json.NET library from James Newton King, and it's pretty awesome but even after reading the included documentation, I have absolutely no idea how to read the JSON file and append data to it.</p>
  
  <p>Are there any samples around that demonstrate how this is done, or can you recommend another library for C# that would allow me to accomplish this?</p>
  
  <h1>Edit</h1>
  
  <p>This is how I am reading a single expense from the json file:</p>
  
  <pre><code>        JObject json = JObject.Parse(data);
          Expense expense = new Expense
          {
              Amount = (string)json["Expense"]["Amount"],
              Due = (string)json["Expense"]["Due"],
              Name = (string)json["Expense"]["Name"]
          };
  
          Debug.Write(expense.Amount);
  </code></pre>