This project has moved and is read-only. For the latest updates, please go here.

How to replace default JSON serialization in ASP.NET

May 8, 2012 at 8:39 PM

I'm writing a web service using ASP.NET 4.0 that is using WebMethods to process and return requests as JSON.  I'd like to replace the default Microsoft JSON serialization/deserialization with JSON.NET. 

This should be a really easy answer to find since its probably a very common use case for the library.  Even if this is not possible, I'd expect to find something saying that.  I've spent at least 3 hours trying to find this answer.  I've looked through the documentation and discussions on this web site.  I searched 2+ hours using Google then Bing (gave up on Google) and finally Alta Vista (gave up on Bing), etc.  Google kept returning results with "JSON" and "NET" but not "JSON.NET" (even when I used quotes).  Anyway, I can't find the answer to this very simple question anywhere! 

What I can find are lots of information about using JSON.NET with MVC or WebAPI.  That's really nice if you're using those, but I'm not.  Maybe the solution is the same or similar, but my experience with ASP.NET is somewhat limited so I don't know all the ins-and-outs of all Microsoft's web technologies.

Could someone please provide an answer to this.  Then may I suggest a very conspicuous page be added to the documentation tree on here titled something like "Integration with ASP.NET".  A page listing all of Microsoft's technologies (ASP.NET 1/2/3/4, MVC 1/2/3/4, WebAPI, WCF, etc) and either instructions or links on how to enable JSON.NET for each of them would be super useful to many new users I'm sure.  And if there are technologies that don't support JSON.NET (for instance ASP.NET v1) just state that clearly under the "ASP.NET 1.0" heading. 

Please, save others from the headache I've been experiencing.

Thanks in advance.

May 8, 2012 at 10:55 PM

You can't.

May 9, 2012 at 5:12 AM

Thanks.  That would explain why I couldn't find anything with all that searching.  Hopefully this question will save others from searching.

Jun 5, 2014 at 10:23 PM
Yes you can. I just did this.

Derive from System.Web.Script.Serialization.JavaScriptConverter and register custom converter in web.config under:
configuration -> system.web.extensions -> scripting -> webServices -> jsonSerialization -> converters
Jun 5, 2014 at 11:22 PM
Actually, no. There is still default serialization after the converter. Oh well...
Jun 13, 2014 at 12:00 AM
Yes you can replace this default json serializer using json serialization
For More Details Follow These links:
Visit us at:
Jun 15, 2014 at 6:34 AM
For MVC - yes, but not for WebForms.