title: Reading and Writing Nested data JSON in C#
body: <p>I have looked at several solutions over the web on reading nested json files but I haven't found one suitable to my need. Maybe because I am new to JSON. Here is my issue:</p>
  <p>I have the following JSON in a file:</p>
  <pre><code>{
    &quot;ConfigError&quot; : {
      &quot;DateSent&quot;: &quot;2022-04-28T14:03:16.6628493-07:00&quot;,
      &quot;ToolType&quot;: &quot;WSM&quot;,
      &quot;IsSent&quot;: true
    },
  
    &quot;FileCopyError&quot; : {
      &quot;DateSent&quot;: &quot;2022-06-14T14:03:16.6628493-07:00&quot;,
      &quot;ToolType&quot;: &quot;RMT&quot;,
      &quot;IsSent&quot;: false
    }
  }
  </code></pre>
  <p>For this I have written two classes. One for the Inner object:</p>
  <pre><code>public class SummaryEmailStatus
      {
          public DateTime DateSent { get; set; }
          public string ToolType { get; set; }
          public bool IsSent { get; set; }
      }
  </code></pre>
  <p>One for the Outer Objects:</p>
  <pre><code>public class SummaryEmailClass
      {
          SummaryEmailStatus Status { get; set; } = new SummaryEmailStatus();
      }
  </code></pre>
  <p>I would like to be able to read the JSON in C#. I'm primarily concerned with the inner objects. They are of same class but they need to be used differently. So ideally I'd want a function that I can pass in &quot;ConfigError&quot; or &quot;FileCopyError&quot; into and it will return SummaryEmailStatus class object populated by the values in the JSON:</p>
  <pre><code>public static void ReadJasonFile(string jsonFileName, string objctName)
          {
              List&lt;SummaryEmailClass&gt; emailClassList = new List&lt;SummaryEmailClass&gt;();
              dynamic jsonFile = JsonConvert.DeserializeObject(File.ReadAllText(jsonFileName));
              SummaryEmailStatus sumclass = jsonFile[objctName];
          }
  </code></pre>
  <p>But this gives me a run time error saying:</p>
  <blockquote>
  <p>Cannot implicitly convert type &quot;Newtonsoft.Json.Linq.JObject to SummaryEmailStatus</p>
  </blockquote>
  <p>How can I successfully parse out the inner <code>summaryemailstatus</code> objects?</p>
  <p><strong>Additionally,</strong> I'd like to be able to create the JSON data within C#. The reason being, when I read the JSON, I will do some task and then will need to update the values of the JSON with the current timestamps. I'd imagine, I'd need to rewrite the file. How can I write a nested JSON like this in C#?</p>
  <p>If JSON is not the best way to do this, I am open to alternatives</p>