title: Convert IQueryable generic to JSON
body: <p>I'm producing a projection via:</p>
  
  <pre><code>var query = from book in books
      select new
      {
          label = book.Title,
          value = book.ID
      };
  </code></pre>
  
  <p>In my razor page I need to use:</p>
  
  <pre><code>    var booksArray = [{
          @(json)
      }];
  </code></pre>
  
  <p>such that the resulting array looks like:</p>
  
  <pre><code>label: 'c++',
  value: 'c++'
  }, {
  label: 'java',
  value: 'java'
  }, {
  label: 'php',
  value: 'php'
  }, {
  label: 'coldfusion',
  value: 'coldfusion'
  }
  </code></pre>
  
  <p>I've come very very close from a couple different approaches - I can get a string that looks correct on the server side but when rendered to the page itself, all the <code>'</code> marks become <code>&amp;#39;</code> .</p>
  
  <p>But focusing on achieving this via JSON.net... </p>
  
  <p>The most likely approach seems like it should be: </p>
  
  <pre><code>var json = JsonConvert.ToString(query);
  </code></pre>
  
  <p>but that tosses:</p>
  
  <pre><code>Unsupported type: System.Linq.Enumerable+WhereSelectListIterator`2[Project.Entity.Book,&lt;&gt;f__AnonymousType3`2[System.String,System.Int32]]. Use the JsonSerializer class to get the object's JSON representation.
  </code></pre>
  
  <p>What's the correct JSON.net syntax?</p>
  
  <p>thx</p>