Any bets on whether or not JavaScriptSerializer will really be obsolete?

Anyone who does a bit AJAXy goodness knows that it's nice and easy to transport simple objects and arrays back and forth to your server as JSON pieces. And hey, if you're doing it right, trying not to be uber chatty and keep it all zippy, you probably aren't doing anything that complex in terms of the objects you're shuttling around.

So why, oh why, would Microsoft mark JavaScriptSerializer as obsolete? The suggested "replacement" is a lot more convoluted: DataContractJsonSerializer. It doesn't even have a good name. What do contracts have to do with me wanting to just turn an array of strings into, well, an array of strings?

Scott Guthrie mentioned in a comment to a blog post of his last year that he was going to try and find out why, and petition for it not to be made obsolete, but I couldn't find any resolution beyond that. All I can say is that two lines that do something productive make a lot more sense than creating stream objects and doing a bunch of other work, and I'd rather not have to add such a thing to my own library code.


  • Thanks for posting on this topic. I too was curious why they marked it obsolete. I'm assuming it had something to do with WCF. I continue to use JavaScriptSerializer regardless.

  • JavaScriptSerializer is used in the MVC Preview 3 to parse objects to JSON.

  • I continue tu use JavaScriptSerializer.

    DataContractJsonSerializer is the class of WCF and we can't do everything with this. JavaScriptSerializer is simpler and better ...

    I hope JavaScriptSerializer will not be deleted, if so, I hope there will be a real alternative !

  • In a comment on one of my blog posts ScottGu mentioned that it's officially un-deprecated.

  • Hooray!

  • I find the DataContractJsonSerializer fairly easy to use. I write a static function that serializes a generic list of an object type and it works a this:

    public static string Serialize(T obj)
    DataContractJsonSerializer serializer = new DataContractJsonSerializer(obj.GetType());

    MemoryStream memoryStream = new MemoryStream();
    serializer.WriteObject(memoryStream, obj);

    return (Encoding.Default.GetString(memoryStream.ToArray()));

    Then because its marked 'static', you can call it really easily:

    List list = new List();
    string json = Serialize(list);


  • I agree the JavaScriptSerializer is easy to use (and it's easy to see where it cannot be used, or might be difficult to use). I don't want to see more convoluted difficult to use APIs, e.g. the XPathNavigator and its namespace hell, but based on opinions expressed in this blog, the DataContractJsonSerializer appears to be demon spawn.

  • Here it says it will be un-deprecated in 3.5 SP1

Comments have been disabled for this content.