Really simple JSON serialization in .NET

Posted by Evgeny on Stack Overflow See other posts from Stack Overflow or by Evgeny
Published on 2010-05-10T03:54:20Z Indexed on 2010/05/10 3:58 UTC
Read the original article Hit count: 334

Filed under:
|
|

I have some simple .NET objects I'd like to serialize to JSON and back again. The set of objects to be serialized is quite small and I control the implementation, so I don't need a generic solution that will work for everything. Since my assembly will be distributed as a library I'd really like to avoid a dependency on some third-party DLL: I just want to give users one assembly that they can reference.

I've read the other questions I could find on converting to and from JSON in .NET. The recommended solution of JSON.NET does work, of course, but it requires distributing an extra DLL.

I don't need any of the fancy features of JSON.NET. I just need to handle a simple object (or even dictionary) that contains strings, integers, DateTimes and arrays of strings and bytes. On deserializing I'm happy to get back a dictionary - it doesn't need to create the object again.

Is there some really simple code out there that I could compile into my assembly to do this simple job?

I've also tried System.Web.Script.Serialization.JavaScriptSerializer, but where it falls down is the byte array: I want to base64-encode it and even registering a converter doesn't let me easily accomplish that due to the way that API works (it doesn't pass in the name of the field).

© Stack Overflow or respective owner

Related posts about .NET

Related posts about JSON