title: ASP.NET Returning JSON with ASHX
body: <p>I am creating autocomplete functionality for my website.
  So far, the javascript part is over. Also, I can get the MembershipUser object of the user that matches.</p>
  
  <p>I need to return JSON in the following format:</p>
  
  <pre><code>{
   query:'Li',
   suggestions:['Liberia','Libyan Arab Jamahiriya','Liechtenstein','Lithuania'],
   data:['LR','LY','LI','LT']
  }
  </code></pre>
  
  <p>and this is the code in ashx:</p>
  
  <pre><code>public void ProcessRequest (HttpContext context) {
      System.Web.Script.Serialization.JavaScriptSerializer JsonSerializer;   
      string query = context.Request.QueryString["query"];
      System.Web.Security.MembershipUserCollection Users = System.Web.Security.Membership.GetAllUsers();
      context.Response.ContentType = "application/json";
      foreach (System.Web.Security.MembershipUser User in Users)
      {
          if (User.UserName.StartsWith(query.ToLower()))
          {
              context.Response.Write(query + Environment.NewLine);
              context.Response.Write(User.Email);
          }
      }
  }
  </code></pre>
  
  <p>How can I return the json in the desired format?
  Thanks.</p>