In the world of AJAX and JavaScript, JSON (JavaScript Object Notation) is ubiquitous; that is, it's everywhere. JSON is, in a nutshell, a terse, convenient mechanism for representing objects and their property values in a manner that the browser (via JavaScript itself) can reconstruct as an object. I'm not going to go into the details of JSON and its intracacies here as there are plenty of other discussions on the topic online elsewhere.
I just wanted to point out that there is some first-class support for JSON serialization in the .NET framework v3.5. I bring this up because a while back I was about to create my own attribute-based JSON serializer but I figured there had to be something already in place for it. I'm glad I looked.
Using the [DataContractAttribute] and [DataMemberAttribute] which are usually associated with Windows Communication Foundation (WCF) you can easily serialize your objects to/from JSON form. The object that provides this support (not coincidentally named DataContractJsonSerializer) is found after referencing the System.ServiceModel.Web assembly in the System.Runtime.Serialization.Json namespace. When (de)serializing your objects, you do so against a stream.
Say, for purposes of the discussion, that you wanted to create an HTTP Handler that returned product information to the caller. You could very easily serialize your product set in the following manner:
void IHttpHandler.ProcessRequest(HttpContext context) {
HttpResponse res = context.Response;
res.ContentType = "application/json";
DataContractJsonSerializer jsSer = new DataContractJsonSerializer(typeof ( Product[] ));
jsSer.WriteObject(res.OutputStream, getProducts());
}
The JavaScript client could then parse the result and do with it as it sees fit. Pretty handy!