In brief, I’m looking for a way move complex object graphs between browser code (jQuery) and server code (ASP.NET MVC). JSON does not support object references, so standard serialization of a circular referencing object is not possible out-of-the-box.
A proposed standard for JSON object references is floating about, which is currently implemented by DoJox, and (apparently) by .NET’s DataContractJsonSerializer class.
While DoJo appears to be a mature JavaScript library, I’m loath to run DoJo side-by-side with jQuery.
Does any one know of a technique or plugin that will allow me to serialize, deserialize complex JSON object graphs with jQuery?
While it doesn’t allow you to serialize circular references, in .NET there is the [ScriptIgnore] attribute you can place on your ViewModels, which will prevent properties from being serialized for JSON and thus avoid the circular reference error so common with complex relations in MVC.
Also, instead of returning your model as-is, using LINQ or anonymous objects to return only the properties you need to represent in your client side script will help you out with performance by minimizing the amount of data being sent to the client.