title: Serialize empty object instead of null in Newtonsoft.JSON
body: <p>this is bothering me for some time. I've got model:</p>
  <pre><code>public class Main
  {
      public Header header { get; set; }
      public Response response { get; set; }
  }
  
  public class Response
  {
      public string projectId { get; set; }
      public string designBriefId { get; set; }
      public MDT mdt { get; set; }
      public List&lt;ReferenceMDT&gt; referenceMDT { get; set; }
      public List&lt;ProductList&gt; ProductList { get; set; }
  
  }
  public class MDT
  {
      [Key]
      public string mdtAssetId { get; set; }
      public bool isMDTDownloaded { get; set; }
      public bool isNamingConventionCorrect { get; set; }
  }
  </code></pre>
  <p>Whenever I'm Serializing this object to a JSON using:</p>
  <pre><code>Newtonsoft.Json
  </code></pre>
  <p>I'm then getting invalid (from API POV I'm working on) JSON conversion on empty/null object:</p>
  <pre><code>{
    &quot;header&quot;: &quot;unimportant&quot;,
    &quot;response&quot;: {
      &quot;projectId&quot;: &quot;Prj_02022022_2&quot;,
      &quot;designBriefId&quot;: &quot;DB_02022022_4&quot;,
      &quot;mdt&quot;: null,
      &quot;referenceMDT&quot;: [],
      &quot;ProductList&quot;: []
    }
  }
  </code></pre>
  <p>Point is that I want to Serialization to output :</p>
  <pre><code>&quot;mdt&quot;: {}
  </code></pre>
  <p>Instead of:</p>
  <pre><code>&quot;mdt&quot;: null
  </code></pre>
  <p>So the question is how can I &quot;mark&quot; this value to be serialized as empty object instead of null or how can it be converted to result in empty object?
  As I mentioned it is bothering me for some time and I'm not sure how to bite this problem. I tried to change whole problem and change it to be Ignored with</p>
  <pre><code>JsonSerializerSettings {NullValueHandling = NullValueHandling.Ignore}
  </code></pre>
  <p>but the problem is that other side of API must receive empty object, and null or lack of object is treated as error.</p>
  <p>As you can see in MDT model, there are mostly bool properties, so whenever I generate object as new() and Ignoring null values it fills all bools with false, generating me an object which is also considered error:</p>
  <pre><code>&quot;mdt&quot;: {
    &quot;mdtAssetId&quot;: null,
    &quot;isMDTDownloaded&quot;: false,
    &quot;isNamingConventionCorrect&quot;: false,
    &quot;isFolderStructureProvidedByAgencyCorrect&quot;: false,
    &quot;heroImageGuidelinesAvailable&quot;: false,
    &quot;allImagesAvailable&quot;: false,
    &quot;isDesignTargetLocked&quot;: false,
    &quot;isPackagingGuidelinesAvailable&quot;: false,
    &quot;isRegulatoryGuidelinesAvailable&quot;: false,
    &quot;mdtResponse&quot;: null,
    &quot;pmaCommentsforMDT&quot;: null
  }
  </code></pre>
  <p>I'll much appreciate any help or even info it is not possible, but if there's difference between empty and null object I think it is resolvable, but I'm too dumb to figure it out.</p>
  <blockquote>
  <p>TL;DR:
  I've got object and whenever I'm trying to serialize it to JSON, it's either returning me null, or object with bool values filled as &quot;false&quot;, which both are error and I need empty object generated.</p>
  </blockquote>