Exploring the CodeFluent Runtime: JsonUtilities
Starting this summer, we added built-in support of JSON/REST services to the WCF Service Model Producer, and around the same period we added a very convenient class to the CodeFluent Runtime (CodeFluent.Runtime.dll): JsonUtilities.
The JsonUtilities class is a simple yet powerful JSON Serializer allowing you to convert your .NET objects into JSON and vice versa. One might ask why didn’t we use one of the many available ones? Well we tried most of them and we bumped into lots of different problems depending on the one used: one supports generics but not serializing the object class, or another one does both but has a strange behavior regarding dates (which by the way is a complex subject in JSON, see this post for more information about this).
Anyway, we thought it could be handy to provide a light JSON serializer (a little more than 1000 lines), which works in .NET 2.0 and upper as well as in Silverlight. Here’s a code sample serializing a collection into JSON:
CustomerCollection customers = CustomerCollection.LoadAll(); string json = JsonUtilities.Serialize(customers);
Keep that in a corner: next time you’ll need to send a JSON stream somewhere, no need to add an extra dependency to your project, you already have what you need in the runtime