title: How to convert a List<T> to specific Json format
body: <p>I want to be able to convert a <code>List&lt;T&gt;</code> into a specific JSON table-like format. In my case, the <code>T</code> will always be a simple object (no nested properties). Here are two examples to illustrate what I want.</p>
  <p><strong>Example #1: <code>List&lt;Person&gt;</code> to JSON</strong></p>
  <pre><code>// C# list of Persons
  var list = new List&lt;Person&gt;() {
    new Person() { First = &quot;Jesse&quot;, Last = &quot;Gavin&quot;, Twitter = &quot;jessegavin&quot; },
    new Person() { First = &quot;John&quot;, Last = &quot;Sheehan&quot;, Twitter = &quot;johnsheehan&quot; }
  };
  
  // I want to transform the list above into a JSON object like so
  {
    columns : [&quot;First&quot;, &quot;Last&quot;, &quot;Twitter&quot;],
    rows: [
      [&quot;Jesse&quot;, &quot;Gavin&quot;, &quot;jessegavin&quot;],
      [&quot;John&quot;, &quot;Sheehan&quot;, &quot;johnsheehan&quot;]
    ]
  }
  </code></pre>
  <p><strong>Example #2: <code>List&lt;Address&gt;</code> to JSON</strong></p>
  <pre><code>// C# list of Locations
  var list = new List&lt;Location&gt;() {
    new Location() { City = &quot;Los Angeles&quot;, State = &quot;CA&quot;, Zip = &quot;90210&quot; },
    new Location() { City = &quot;Saint Paul&quot;, State = &quot;MN&quot;, Zip = &quot;55101&quot; },
  };
  
  // I want to transform the list above into a JSON object like so
  {
    columns : [&quot;City&quot;, &quot;State&quot;, &quot;Zip&quot;],
    rows: [
      [&quot;Los Angeles&quot;, &quot;CA&quot;, &quot;90210&quot;],
      [&quot;Saint Paul&quot;, &quot;MN&quot;, &quot;55101&quot;]
    ]
  }
  </code></pre>
  <p>Is there a way to tell JSON.net to serialize an object in this manner? If not, how could I accomplish this? Thanks.</p>
  <h2>UPDATE:</h2>
  <p>Thanks to @Hightechrider's answer, I was able to write some code that solves the problem.</p>
  <p>You can view a working example here <a href="https://gist.github.com/1153155" rel="nofollow noreferrer">https://gist.github.com/1153155</a></p>