title: How can I generate a JavaScript object literal in C#?
body: <p>I need to create the following JavaScript object literal in C# code, as a string, and am looking for some tips on how to best do this.</p>
  
  <pre><code>model: {
      id: "Id",
      fields: {
          Surname: { type: "string", validation: { required: true } },
          FirstName: { type: "string", validation: { required: true } },
          PrivateEmail: { type: "string", validation: { required: true } },
          DefaultPhone: { type: "string" },
          CompanyName: { type: "string" },
          CreateDate: { type: "date" },
          LastLoginDate: { type: "date" },
          IsLockedOut: { type: "boolean" }
      }
  }
  </code></pre>
  
  <p>This defines a client side object with a <em>model</em> property that reflects what each row in my MVC4 view model will look like. I can use plain reflection to generate a string literal, but I would rather somehow tap into already available JSON serialization services in .NET. To do so I think I would need to create an anonymous object with properties corresponding to the JS properties above. How could I do this?</p>
  
  <p><strong>EDIT:</strong>
  I need to loop over the properties in a view model class and generated a C# object that will serialize to a JavaScript 'transform' of the view model class similar to the one above.</p>