Json.NET 4.0 Release 8 – Bug fixes

This is a relatively minor release that fixes all outstanding bugs and adds a couple of enhancements.

NuGet Silverlight/Windows Phone Assemblies No Longer Strong-Named

The big change this release is that the Silverlight/Windows Phone NuGet assemblies are no longer strong-named.

Unfortunately Silverlight/Windows Phone applications do not support redirecting strong-named assemblies like normal .NET apps do via <assemblyBinding> configuration. If a Silverlight or Windows Phone application uses two libraries that each reference a different version of Json.NET then the only solution is to get the source code for the libraries and recompile them yourself to use the same version of Json.NET – not ideal.

From 4.0.8 the NuGet assemblies for Silverlight/Windows Phone are no longer strong-named. If you do need strong-named versions of Json.NET for SL/WP then they are still available in the Json.NET zip download from CodePlex in the Bin\Silverlight\Signed and Bin\WindowsPhone\Signed zip folders. I don’t recommend using them with reusable SL/WP libraries because of the reasons above.

Json.NET Assembly Redirection

In case you ever do end up with multiple libraries that reference different versions of Json.NET in a normal .NET application, here is the configuration to fix your application use one version of Json.NET:

      <assemblyIdentityname="Newtonsoft.Json"publicKeyToken="30ad4fe6b2a6aeed" />
      <bindingRedirectoldVersion=""newVersion="" />

Update newVersion as needed to the version of Json.NET you are using. This can be found in Visual Studio by right-clicking on Newtonsoft.Json reference and selecting Properties.

Mr. Simpson, you're smarter than you look, or sound, or our best testing indicates.


Here is a complete list of what has changed since Json.NET 4.0 Release 6 (if you’re curious where v7 is, it was a minor release to fix a couple of urgent bugs).

  • New feature - Added VersionConverter for System.Version
  • New feature - Added a JSON schema IsValid overload that returns a list of error messages
  • Change - NuGet Silverlight/Windows Phone assembies are no longer strong-named
  • Fix - Fixed Json.NET attributes on nullable struct properties not being used
  • Fix - Fixed deserializing nullable enums
  • Fix - Fixed JsonConstructor incorrectly being allowed on properties
  • Fix - Fixed empty string being changed to null when deserializing object properties
  • Fix - Fixed not replacing ignored properties when resolving an object's contract
  • Fix - Fixed JsonReader.ReadAsDateTimeOffset throwing an incorrect error message
  • Fix - Fixed error when converting XML to JSON with a default namespace
  • Fix - Fixed JsonValidatingReader.ReadAsBytes throwing an exception
  • Fix - Fixed a unit test failing because of the running computer’s timezone


Json.NET CodePlex Project

Json.NET 4.0 Release 8 Download – Json.NET source code, documentation and binaries

Json.NET 4.0 Release 6 – Serialization Performance

The big feature of this release is improved performance. For the first time in a couple of years I’ve sat down and benchmarked, profiled and tuned Json.NET.

And now, in the spirit of the season: start shopping. And for every dollar of Krusty merchandise you buy, I will be nice to a sick kid. For legal purposes, sick kids may include hookers with a cold.

For all its features Json.NET was already fast but there are improvements in JsonTextReader which I rewrote and object deserilization. Json.NET is faster than both .NET framework JSON serializers in all scenarios again.

Improved error messages

One of the nice features of JsonTextReader is that it keeps track of its current line number and line position and includes that information when it encounters bad JSON.

This release adds that line number and position information to deserialization errors. Now deserialization should be much easier to troubleshoot.

string json = @"[
List<int> numbers = JsonConvert.DeserializeObject<List<int>>(json);
// Error converting value {null} to type 'System.Int32'. Line 5, position 7.

Worst. Bug. Ever. Fixed.

Visual Studio Ultimate Edition has a feature called Intellitrace. Intellitrace and Json.NET didn’t get along. After a year of at first being unsure why only some people were getting the error, and then not knowing what exactly why Intellitrace was breaking Json.NET, I finally nailed it down to one three line method that Intellitrace didn’t like. Fixed... finally.


Here is a complete list of what has changed since Json.NET 4.0 Release 4 (if you’re curious where v5 is, it was just one fix for Windows Phone Mango and NuGet).

  • New feature - Added line number information to deserialization errors
  • New feature - Added ReadAsInt32 to JsonReader
  • New feature - Added BinaryReader/BinaryWriter constructor overloads to BsonReader/BsonWriter
  • Change - JsonTextReader error message when additional JSON content found is more descriptive
  • Fix - Removed unused utility methods
  • Fix - Fixed elusive Intellitrace runtime destabilization error
  • Fix - Fixed internal exception thrown when deserializing Decimal/DateTimeOffset/Byte lists
  • Fix - Fixed potential multi-threading serializing issue
  • Fix - Fixed serializing types that hides a base classes property with a proeprty of the same name
  • Fix - Fixed BsonReader to use BinaryReader instead of base stream
  • Fix - Fixed referencing the NuGet package from Windows Phone 7.1 projects


Json.NET CodePlex Project

Json.NET 4.0 Release 6 Download – Json.NET source code, documentation and binaries

Json.NET 4.0 Release 4 – Bug fixes

This release contains bug fixes and some minor changes.

Custom type names with TypeNameHandling

Note that support for custom type names was added in a previous Json.NET release.

One commonly asked for feature is the ability to customize the value of the $type property when using TypeNameHandling. Fortunately new in .NET 4 is the virtual SerializationBinder.BindToName method that translates a Type to a custom string.

To customize the $type property in Json.NET just create a class that inherits from SerializationBinder and override the BindToName and the BindToType methods with your custom naming logic. The example SerializationBinder example below serializes types to just their name without any namespace or assembly information, those details are passed into the binder itself via a constructor parameter and used during deserialization.

public class TypeNameSerializationBinder : SerializationBinder
  public string TypeFormat { get; private set; }
  public TypeNameSerializationBinder(string typeFormat)
    TypeFormat = typeFormat;
  public override void BindToName(Type serializedType, out string assemblyName, out string typeName)
    assemblyName = null;
    typeName = serializedType.Name;
  public override Type BindToType(string assemblyName, string typeName)
    string resolvedTypeName = string.Format(TypeFormat, typeName);
    return Type.GetType(resolvedTypeName, true);

The simplest way to use a custom serialization binder is with JsonConvert and JsonSerializerSettings.

TypeNameSerializationBinder binder = new TypeNameSerializationBinder("YourAppNamespace.{0}, YourAppAssembly");
IList<object> values = new List<object>
    new Customer
        Name = "Caroline Customer"
    new Purchase
        ProductName = "Elbow Grease",
        Price = 5.99m,
        Quantity = 1
string json = JsonConvert.SerializeObject(values, Formatting.Indented, new JsonSerializerSettings
  TypeNameHandling = TypeNameHandling.Auto,
  Binder = binder
//  {
//    "$type": "Customer",
//    "Name": "Caroline Customer"
//  },
//  {
//    "$type": "Purchase",
//    "ProductName": "Elbow Grease",
//    "Price": 5.99,
//    "Quantity": 1
//  }

To deserialize just reuse the custom SerializationBinder with DeserializeObject.


Here is a complete list of what has changed since Json.NET 4.0 Release 3.

  • Change - JsonTextReader.Culture is now CultureInfo.InvariantCulture by default
  • Change - KeyValurPairConverter no longer depends on the order of the key and value properties
  • Change - Time zone conversions now use new TimeZoneInfo instead of TimeZone
  • Fix - Fixed boolean values sometimes being capitalized when converting to XML
  • Fix - Fixed error when deserializing ConcurrentDictionary
  • Fix - Fixed serializing some Uris returning the incorrect value
  • Fix - Fixed occasional error when converting non-long integer properties to XML
  • Fix - Fixed deserializing byte arrays with type name information
  • Fix - Fixed flag enum items not being correctly camel cased
  • Fix - Fixed JsonValidatingReader validating the first array item twice
  • Fix - Fixed JsonSchema not correctly validating integers as a subset of decimal
  • Fix - Fixed bad BSON when writing long strings of complex UTF8 characters
  • Fix - Fixed error not being raised for additional content in JSON string for JArray.Parse and JObject.Parse
  • Fix - Fixed DataTableConverter including nulls with NullValueHandling.Ignore


Json.NET CodePlex Project

Json.NET 4.0 Release 4 Download – Json.NET source code, documentation and binaries

Json.NET 4.0 Release 3 – LINQ to JSON performance

One of Json.NET’s most popular features - LINQ to JSON – has gotten a speed boost.

Previously the LINQ to JSON collection objects (JObject and JArray) internally used a linked list to keep track of their children. While this gave them complete control over the order of properties inside objects, it made lookups by key (a property name for an object, an index for an array) slow over large JSON documents.

Json.NET 4.0 Release 3 changes the internal structure of the collection objects to eliminate linked lists – JArray now uses a list internally to store child values and JObject uses a combination of a list and dictionary, letting it preserve property order and make property name lookups O(1).

I'll have to read Marge's book, and I swore never to read again after To Kill a Mockingbird gave me no useful advice on killing mockingbirds. It did teach me not to judge a man based on the color of his skin, but what good does that do me?

From your perspective the API for LINQ to JSON is exactly the same, it is just faster.

Assembly file names

One thing to note in this release is that to play nicely with NuGet the different versions of Json.NET now all use the same assembly file name: Newtonsoft.Json.dll

If you want to find out exactly which version of the dll you are using the Windows file properties dialog display’s a .NET assembly’s title as the File description.

Oh no, the Pawnee have returned. They probably want their souls back.


Here is a complete list of what has changed since Json.NET 4.0 Release 2.

  • New feature - Improved support for deserializing objects using non-default constructors
  • New feature - JsonConverterAttribute now allowed on constructor parameters
  • New feature - JsonPropertyAttribute now allowed on constructor parameters
  • New feature - Added Serializable attribute to exceptions
  • New feature - JsonObject and JsonProperty attributes can now be placed on an interface and used when serializing implementing objects
  • New feature - Improve TypeNameHandling.Auto to skip adding an unneeded type name for collection interfaces
  • New feature - LINQ to JSON internals rewritten to use lists and dictionaries rather than linked lists
  • New feature - Added support for deserializing to readonly collections and dictionaries on classes with non-default constructors
  • New feature - Added serialization constructors to all Exceptions
  • New feature - Added support for serialization event attributes on base classes
  • New feature - Added support for BindToName on SerializationBinder
  • New feature - Missing JSON errors can now be handled using JsonSerializer error handling
  • New feature - Added Populate and IgnoreAndPopulate options to DefaultValueHandling for automatically populating default values during deserialization
  • New feature - Added support for setting readonly fields when marked up with JsonPropertyAttribute
  • New feature - Added Order to JsonPropertyAttribute to override the order of serialized JSON
  • New feature - Added Culture to JsonTextReader to use when converting values from JSON text
  • New feature - Added support for reading byte arrays from JSON integer arrays
  • New feature - Added support for deserializing IDictionary properties
  • New feature - Added ToObject to JToken for deserializing LINQ to JSON objects to a .NET object
  • New feature - Added support for Guid, TimeSpan and Uri to LINQ to JSON
  • Change - Changed WriteEndObject, WriteEndArray, WriteEndConstructor on JsonWriter to be virtual
  • Change - Moved JPropertyDescriptor to Newtonsoft.Json.Linq namespace
  • Change - Additional content after the $ref property now ignored when reading schema references
  • Change - Changed JToken.Children to return an empty iterator rather than erroring
  • Change - Changed the assembly file names to all be Newtonsoft.Json.dll to fix NuGet referencing
  • Change - Changed $id and $ref properties to allow null
  • Fix - Changed .NET 2.0 version to use LinqBridge source code rather than ilmerge to fix error
  • Fix - Fixed deserializing to IEnumerable<T> properties
  • Fix - Fixed DataTable and DataColumn names not being modified by CamelCasePropertyNamesContractResolver
  • Fix - Fixed JObject loading JSON with comments
  • Fix - Fixed error when using a Specified property with no setter
  • Fix - Fixed transient constructor error on Windows Phone 7
  • Fix - Fixed deserializing null values into nullable generic dictionaries
  • Fix - Fixed potential casting error when writing JSON using a JsonReader
  • Fix - Fixed converting emtpy XML elements with an array attribute not writing other attributes
  • Fix - Fixed deserializing null values into DataTables
  • Fix - Fixed error when deserializing readonly IEnumerable<T> array properties
  • Fix - Fixed not including type name for byte[] values
  • Fix - Fixed BsonWriter failing silently when writing values outside of an Object or Array
  • Fix - Fixed serializer attempting to use dynamic code generation in partial trust
  • Fix - Fixed serializing objects with DataContract and DataMember attributes on base classes


Json.NET CodePlex Project

Json.NET 4.0 Release 3 Download – Json.NET source code, documentation and binaries