title: Serialize Object into Array
body: <p>I have a C# object.  I want to serialize it to an array rather than a key-value map.</p>
  
  <p>My C# class:</p>
  
  <pre><code>[JsonArray()]
  public class Foo
  {
      [JsonProperty(Order = 1)]
      public Boolean Bar = true;
  
      [JsonProperty(Order = 2)]
      public Boolean Baz = false;
  }
  </code></pre>
  
  <p>The desired JSON output:</p>
  
  <pre><code>[true,false]
  </code></pre>
  
  <p>The actual JSON output (if I remove the JsonArray attribute at the top):</p>
  
  <pre><code>{"Bar":true,"Baz":false}
  </code></pre>
  
  <p>I have a large number of objects in a complex object hierarchy that I need to have serialized as an array rather than key-value map.  I would prefer a solution that doesn't require that the thing doing the serialization know anything about what it is serializing.  I want to be able to just call JsonConvert.SerializeObject(myThing) on a top level object and have all of the sub-objects serialize correctly due to attributes they have on themselves.</p>
  
  <p>Currently, I have all of my objects implement IEnumerable and then I manually teach each one of them how to return the properties in the correct order but this causes confusion when working in C# because intellisense tries to offer me all of the LINQ operations on the object even though none of them are appropriate.</p>
  
  <p>I believe it is possible, though I don't know how, to add an attribute to Foo that points at another class that knows how to serialize Foo.  Something like <code>[JsonConverter(FooSerializer)]</code> and then <code>FooSerializer</code> would implement <code>JsonConverter</code>.  However, I am struggling to find much information on how to use JsonConverter for serialization, most of the questions people ask seem to be related to deserialization.</p>