title: Ignoring null fields in Json.net
body: <p>I have some data that I have to serialize to JSON. I'm using JSON.NET. My code structure is similar to this:</p>
  
  <pre><code>public struct structA
  {
      public string Field1;
      public structB Field2;
      public structB Field3;
  }
  
  public struct structB
  {
      public string Subfield1;
      public string Subfield2;
  }
  </code></pre>
  
  <p>Problem is, my JSON output needs to have ONLY <code>Field1</code> OR <code>Field2</code> OR <code>Field3</code> - it depends on which field is used (i.e. not null). 
  By default, my JSON looks like this:</p>
  
  <pre><code>{
      "Field1": null,
      "Field2": {"Subfield1": "test1", "Subfield2": "test2"},
      "Field3": {"Subfield1": null, "Subfield2": null},
  }
  </code></pre>
  
  <p>I know I can use <code>NullValueHandling.Ignore</code>, but that gives me JSON that looks like this:</p>
  
  <pre><code>{
      "Field2": {"Subfield1": "test1", "Subfield2": "test2"},
      "Field3": {}
  }
  </code></pre>
  
  <p>And what I need is this:</p>
  
  <pre><code>{
      "Field2": {"Subfield1": "test1", "Subfield2": "test2"},
  }
  </code></pre>
  
  <p>Is there simple way to achieve this? </p>