title: How to ignore null array elements with Newtonsoft JSON serializer
body: <p>I'm attempting to serialize an object array, but I need it to ignore null elements. I realize I could simply have logic upon deserialization that checks for the nulls, however I don't want to write unnecessary data over the network. The array can have a maximum of 9 elements, but all 9 indices are not used in every instance. I understand that a list could be utilized, but for efficiency sake I do not wish to do that. </p>
  
  <p>Per similar questions I've browsed on this site, I've attempted to add the following tag to the array: <code>[JsonProperty(NullValueHandling = NullValueHandling.Ignore)]</code></p>
  
  <p>However, this approach does not ignore null elements. </p>
  
  <pre><code>[JsonProperty(NullValueHandling = NullValueHandling.Ignore)]
  public Node[] Nodes { get; } 
  public void Init() 
  {
      Nodes = new Node[9];
  }
  public string Encode()
  {
      return JsonConvert.SerializeObject(Nodes, Formatting.None);
  }
  </code></pre>
  
  <p>Is there an elegant solution to this? </p>