title: Serialize object using Json.NET with valid javascript format
body: <p>Does anyone know how to serialize object as the follow code using Json.NET? </p>
  
  <pre><code>class Program
  {
      static void Main(string[] args)
      {
          var dic = new Dictionary&lt;string, object&gt;();
          dic.Add("key", true);
          dic.Add("create", false);
          dic.Add("title", "Name");
          dic.Add("option2", @"function(value){ return value; }");
          dic.Add("fields", new Dictionary&lt;string, object&gt;
          {
              {"Id", new Dictionary&lt;string, object&gt;
                     {
                         {"title", "This is id"}
                     }
              }
          });
          Console.WriteLine(Newtonsoft.Json.JsonConvert.SerializeObject(dic, Formatting.Indented));
      }
  }
  </code></pre>
  
  <p>Result output is a json string:</p>
  
  <pre><code>{
    "key": true,
    "create": false,
    "title": "Name",
    "option2": "function(value){ return value; }",
    "fields": {
      "Id": {
        "title": "This is id"
      }
    }
  }
  </code></pre>
  
  <p>But I expect it as the following code (it looks like javascript hash):</p>
  
  <pre><code>{
    key: true,
    create: false,
    title: "Name",
    option2: function(value){ return value; },
    fields: {
      Id: {
        title: "This is id"
      }
    }
  }
  </code></pre>
  
  <p>The below code will show the output as I expect. But I need a different solution. Please help me. Thank you</p>
  
  <pre><code>    private static void SerializeObject(IDictionary&lt;string, object&gt; dic)
      {
          Console.WriteLine("{");
          foreach (var key in dic.Keys)
          {
              var value = dic[key];
              if (value is JsFunction)  // just a wrapper class of string
              {
                  Console.WriteLine("{0}: {1}", key, value);
              }
              else if (value is IDictionary&lt;string, object&gt;)
              {
                  Console.WriteLine("{0}:", key);
                  SerializeObject(value as IDictionary&lt;string, object&gt;);
              }
              else
              {
                  Console.WriteLine("{0}: {1}", key, JsonConvert.SerializeObject(dic[key]));
              }
          }
          Console.WriteLine("}");
      }
  </code></pre>