title: Parse Nested JSON and replace data in C#
body: <p>I have a complex JSON response that i need to parse and replace data in.</p>
  
  <p>This is just a snip from 1 day but need to do all days in the response.</p>
  
  <p>How can i parse this and just change values. 
  I need to modify and send back to the host.</p>
  
  <pre><code>  {
    "schedulePeriods":` [
      {
        "day": "Monday",
        "periodType": "WakeOcc1",
        "startTime": 26,
        "isCancelled": false,
        "heatSetpoint": 70.0,
        "coolSetpoint": 75.0,
        "fanMode": "Auto"
      },
      {
        "day": "Monday",
        "periodType": "LeaveUnocc1",
        "startTime": 32,
        "isCancelled": false,
        "heatSetpoint": 65.0,
        "coolSetpoint": 75.0,
        "fanMode": "Auto"
      },
      {
        "day": "Monday",
        "periodType": "ReturnOcc2",
        "startTime": 66,
        "isCancelled": false,
        "heatSetpoint": 72.0,
        "coolSetpoint": 75.0,
        "fanMode": "Auto"
      },
      {
        "day": "Monday",
        "periodType": "SleepUnocc2",
        "startTime": 0,
        "isCancelled": false,
        "heatSetpoint": 65.0,
        "coolSetpoint": 75.0,
        "fanMode": "Auto"
      },
      {
        "day": "Tuesday",
        "periodType": "WakeOcc1",
        "startTime": 26,
        "isCancelled": false,
        "heatSetpoint": 70.0,
        "coolSetpoint": 75.0,
        "fanMode": "Auto"
      },
  </code></pre>
  
  <p>so what i have now is this:` </p>
  
  <pre><code>class Day
      {
          public string day { get; set; }
          public string periodType { get; set; }
          public int startTime { get; set; }
          public double heatSetpoint { get; set; }
          public double coolSetpoint { get; set; }
  
  
          public override string ToString()
          {
              return string.Format("{0}\n{1}\n{2}\n{3}\n{4}", day, periodType, startTime, heatSetpoint, coolSetpoint);
          }
      }
  
      static void Main(string[] args)
      {
  
           String JSONstring = File.ReadAllText("json.json");
           JObject o = JObject.Parse(JSONstring);
  
  
           string day = (string)o.SelectToken("schedulePeriods[0].day");
           string periodType = (string)o.SelectToken("schedulePeriods[0].periodType");
           int startTime = (int)o.SelectToken("schedulePeriods[0].startTime");
           double heatSetpoint = (double)o.SelectToken("schedulePeriods[0].heatSetpoint");
           double coolSetpoint = (double)o.SelectToken("schedulePeriods[0].coolSetpoint");
           Console.WriteLine("{0}\n{1}\n{2}\n{3}\n{4}",day,periodType,startTime,heatSetpoint,coolSetpoint);
  
  
           Console.WriteLine("Change Value to:");
           string answer = Console.ReadLine();
  
           day = answer;
  
  
           Console.WriteLine("new value {0}", day);
                string data = JsonConvert.SerializeObject(JSONstring,Formatting.Indented);
               File.WriteAllText("newfile.json", data);
                Console.ReadLine();
  </code></pre>
  
  <p>}</p>
  
  <p>i can get the data from first curly braces but no further.
  I need to get from each array.
  i also want to modify a given entry and then save the edited file with proper json formatting(this is not working at all)`</p>
  
  <p>SOLVED.
  Thank you for your feedback</p>