Archives / 2013 / April
  • Json.NET 5.0 Release 4 – Performance

    This release of Json.NET ships with many performance improvements, and is over 30% faster serializing and deserializing JSON compared to Json.NET 4.5.

    Smithers, release the hounds.

    Json.NET extends its performance lead over DataContractJsonSerializer and continues to be significantly faster than JavaScriptSerializer which is used by ASP.NET MVC.

    Compiled Expressions on Windows 8 and Windows Phone 8

    An additional performance improvement specific to Windows 8 and Windows Phone 8 is the switch from the serializer internally using latebound reflection to compiled expressions. In exchange for a small one off cost the first time a type is serialized, compiled expressions are considerably faster than latebound reflection and provide an additional speed boost to Json.NET on Win8 and WP8.


    Here is a complete list of what has changed since Json.NET 5.0 Release 1.

    • New feature - Added JsonWriter.SetWriteState to support inheritance from JsonWriter implementations
    • Change - Changed .NET 4.5 portable library and WinRT library to use compiled expressions reflection
    • Fix - Fixed error serializing non-generic types that implement IEnumerable<T>


    Json.NET CodePlex Project

    Json.NET 5.0 Release 4 Download – Json.NET source code and assemblies

  • Json.NET 5.0 Release 1 – .NET 4.5, BigInteger, Read-Only Collections

    New and Updated Libraries

    In Json.NET 5.0 there are a bunch of library version changes:

    • Added .NET 4.5 library
    • Added portable library targeting .NET 4.5 + WP8 + Win8
    • Removed the Silverlight library.
    • Removed the Windows Phone library

    Upgrading library versions allows Json.NET to support new .NET features such as dynamic and async across more platforms.

    A baseline portable class library still supports all platforms (.NET 4 + WP7 + SL5 + Win8) so have no fear  Silverlight and Windows Phone developers, even though the dedicated libraries have been removed you can continue use the latest version of Json.NET on Silverlight/Windows Phone with a portable class library.

    Note that the assembly version number of Json.NET 5.0 hasn't changed and is still to avoid assembly redirect issues. Read more about assembly version numbers here.

    Serializing NaN and Infinity Floating Point Values

    Json.NET no longer serializes NaN and positive and negative infinity floating point values as symbols, which is invalid JSON. With 5.0 the new default is to serialize those values as strings, e.g. "NaN" instead of NaN. There is no change to serializing normal floating point numbers.

    A FloatFormatHandling setting has been added so you can control how NaN and infinity values are serialized.

    string json;
    IList<double> d = new List<double> {1.1, double.NaN, double.PositiveInfinity};
    json = JsonConvert.SerializeObject(d);
    // [1.1,"NaN","Infinity"]
    json = JsonConvert.SerializeObject(d, new JsonSerializerSettings {FloatFormatHandling = FloatFormatHandling.Symbol});
    // [1.1,NaN,Infinity]
    json = JsonConvert.SerializeObject(d, new JsonSerializerSettings {FloatFormatHandling = FloatFormatHandling.DefaultValue});
    // [1.1,0.0,0.0]

    BigInteger and Read-Only Collections

    Json.NET 5.0 adds support for BigInteger. Now when reading and writing JSON there is no limit on the maximum size of integers Json.NET can handle.

    There is also support for read-only collection interfaces (IReadOnlyList<T> and IReadOnlyDictionary<TKey, TValue>) which were added in .NET 4.5. As long as there is an IEnumerable<T> constructor then Json.NET will deserialize to the read-only collection for you.

    string json = @"[
    var l = JsonConvert.DeserializeObject<IReadOnlyList<BigInteger>>(json);
    BigInteger nineQuindecillionAndOne = l[0];
    // 9000000000000000000000000000000000000000000000001


    There are many performance and memory improvements in Json.NET 5.0, especially when serializing and deserializing collections, and Json.NET in Windows 8 Store apps.


    Here is a complete list of what has changed since Json.NET 4.5 Release 11.

    • New feature - Added .NET 4.5 library
    • New feature - Added portable library targeting .NET 4.5, Win8, WP8
    • New feature - Added Path to JToken
    • New feature - Added BigInteger support
    • New feature - Added IReadOnlyCollection<T> and IReadOnlyDictionary<TKey, TValue> support
    • New feature - Added FloatFormatHandling to JsonWriter/JsonSerializer/JsonSerializerSettings
    • New feature - Added DateFormatString to JsonWriter/JsonSerializer/JsonSerializerSettings
    • New feature - Added support for multiple serialization events and use base type serialization events
    • New feature - Added DeserializeAnonymousType overload with JsonSerializerSettings
    • New feature - Added support for specifying root type when serializing JSON with TypeNameHandling.Auto
    • New feature - Added support for creating lists and dictionaries with an IEnumerable<T> constructor
    • New feature - Added IConvertible support to JValue
    • New feature - Added support for serializing custom IConvertible values
    • New feature - Added support for deserializing IList
    • New feature - Added support for converting byte array JValues to Guid
    • New feature - Added support for deserializing byte arrays to Guid
    • Change - NaN and Infinity floating point values are serialized as strings by default
    • Change - Minor breaking changes to JsonSchema type
    • Change - Upgraded Windows Phone assembly to WP8
    • Change - DateTime IDictionary keys are now serialized in ISO date format
    • Change - DataContractAttribute is no longer inherited to match DataConctractSerializer behavior
    • Change - StringEnumConverter converts empty strings to null for nullable enums
    • Change - Guids serialize to a binary UUID in BSON instead of a string
    • Remove - Removed SL4 library
    • Remove - Removed WP7 library
    • Fix - Fixed JTokenWriter returning a null reference
    • Fix - Fixed static fields to no longer be included with fields serialization
    • Fix - Fixed recursively reading type wrapper objects when deserializing
    • Fix - Fixed incorrect namespace when converting XML to JSON
    • Fix - Fixed poor performance when serializing/deserialize dynamic objects
    • Fix - Fixed StringEnumConverter to throw JsonSerializerException on error
    • Fix - Fixed hidden properties not being serialized


    Json.NET CodePlex Project

    Json.NET 5.0 Release 1 Download – Json.NET source code and assemblies